I am new to WCF service. I created a simple asp.net web application and called a SharePoint Admin web-service to create a site. Following is the code.
protected void btnSubmit_Click(object sender, EventArgs e)
{
CreateSiteClass objCreateSiteClass = new CreateSiteClass();
objCreateSiteClass.CreateSite(txtSiteName.Text);
}
[WebServiceBindingAttribute(Name = "AdminSoap", Namespace = "http://schemas.microsoft.com/sharepoint/soap/")]
public class CreateSiteClass : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public void CreateSite(string str)
{
try
{
AdminService.Admin admService = new AdminService.Admin();
//admService.Credentials = System.Net.CredentialCache.DefaultCredentials;
admService.Credentials = new System.Net.NetworkCredential("ashish.rautela", "badri@12345", "IRISSOFTWARE");
admService.CreateSite(str, "Title", "Description", 1033, "STS#0", "IRISSOFTWARE\\ashish.rautela", "Ashish Rautela", "ashish.rautela@irissoftware.com", "", "");
}
catch (System.Web.Services.Protocols.SoapException ex)
{
Console.WriteLine(ex.StackTrace);
}
}
}
This successfully created the site (whatever you will pass in the function parameter)
But my requirement is to use this service inside an WCf service. So, i created a WC开发者_如何学GoF application and wrote the same function in my Service1 class that implements the IService1 interface.
The WCF service was build successfully and when i browsed it after creating a virtual directory it gave me the following path:-
http://vm-sp-vishal.irissoftware.com:8888/WCFSiteCreateor/Service1.svc?wsdl
After this i created a simple asp.net web application and added a service reference in my project by right clicking-->Add service Reference. Then i wrote the following code in my default.aspx.cs
protected void btnid_Click(object sender, EventArgs e)
{
TestService(txt.Text);
}
protected void TestService(string strUrl)
{
MyWCFAdminService.Service1Client objMyWCFAdminService = new MyWCFAdminService.Service1Client();
objMyWCFAdminService.SiteCreatorClass(strUrl);
}
But when i run this application and pass the function parameter into an textbox, it gives me a access denied error.
I am a farm administrator member in the SharePoint server where i am running this code.
Any help?
it sounds like you need to sort out your access policies as you will be going cross domain ...
you may need a clientaccesspolicy.xmlm file in the root of your wcf services (or the sdharepoint ones)
its contents need to be something like this
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from>
<domain uri="*"/>
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Obviously that one is not secure ;) ill le tyou figure that bit out.
精彩评论