SharePoint, WCF and Anonymous Access - sharepoint

Does a WCF service on SharePoint require that Anonymous Access is enabled?
We have an application page which is calling the service using Ajax.Net, if Anon Access is off then we get prompted for the username and password, if it is on then all is well.
We are not using a WCF client, it is purely being called by the scriptmanager
<configuration>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding
name="webHttpBinding_DataSources"
maxBufferSize="5242880"
maxReceivedMessageSize="5242880" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior
name="ServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior
name="ServiceBehavior">
<serviceMetadata
httpGetEnabled="true"
httpGetUrl="" />
<serviceDebug
includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true"/>
<services>
<service
name="XXXXXXXX.DataSources.Services.DataSourceHelper"
behaviorConfiguration="ServiceBehavior">
<endpoint
address=""
behaviorConfiguration="ServiceAspNetAjaxBehavior"
binding="webHttpBinding"
bindingConfiguration="webHttpBinding_DataSources"
contract="XXXXXXXX.DataSources.Services.IDataSourceHelper" />
</service>
</services>
</system.serviceModel>
</configuration>
Thanks, Phill

I managed to get it working with the following
<configuration>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding
name="webHttpBinding_DataSources"
maxBufferSize="5242880"
maxReceivedMessageSize="5242880" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior
name="ServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior
name="ServiceBehavior">
<serviceMetadata
httpGetEnabled="true"
httpGetUrl="" />
<serviceDebug
includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true"/>
<services>
<service
name="XXXXXXXXXX.DataSources.Services.DataSourceHelper"
behaviorConfiguration="ServiceBehavior">
<endpoint
address=""
behaviorConfiguration="ServiceAspNetAjaxBehavior"
binding="webHttpBinding"
bindingConfiguration="webHttpBinding_DataSources"
contract="XXXXXXXXXX.DataSources.Services.IDataSourceHelper" />
</service>
</services>
</system.serviceModel>
</configuration>
I did an IISReset and had to close and re-open my browser to get it working though
Best Regards,
Phill

Related

WCF service giving no response with TCP and Http protocols from azure

Have two clients to use the service the two protocls
<system.serviceModel>
<services>
<Service name ="ServcieName">
<endpoint address ="" binding="basicHttpBinding" contract="ContractName">
</endpoint>
<endpoint address ="" binding="netTcpBinding" contract="ContractName">
</endpoint>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I want a responses from both the end points.
The namespace system.serviceModel need to be used in the project, as this converts the interface into a service model.
Config file:
In the configuration file for communicating with the Service need to use the Mex behaviour as a service Behaviour
<serviceMetadata httpGetEnabled="true"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
And for 2 different bindings, need to use
<endpoint address="SampleService" binding="basicHttpBinding" contract="SampleService.ISampleService"/>
<endpoint address="SampleService" binding="netTcpBinding" contract="SampleService.ISampleService"/>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="SampleService.SampleService" behaviorConfiguration="mexBehaviour">
<endpoint address="SampleService" binding="basicHttpBinding" contract="SampleService.ISampleService"/>
<endpoint address="SampleService" binding="netTcpBinding" contract="SampleService.ISampleService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://loclahost:8080"/>
<add baseAddress="net.tcp://loclahost:8090"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Sample service code
public class SampleService : ISampleService
{
public string GetMessage(string name)
{
return " Hello " + name;
}
}

Getting 413 Payload too large then 500 System.ServiceModel.ServiceActivationException when i increase maxReceivedMessage in my WCF sharepoint app

I developed a wcf webservice in a sharepoint 2016 on premise environment.
When I try to upload a long body I used to get a 413 payload too large error so I changed my app.config to this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="ilem.Sharepoint.WebServices.ISAPI.ilemGroupWS.Service">
<endpoint address="" binding="basicHttpBinding" contract="ilem.Sharepoint.WebServices.ISAPI.ilemGroupmWS.IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/ilem.Sharepoint.WebServices.ISAPI.ilemGroup/Service/" />
</baseAddresses>
</host>
</service>
</services>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name=""
helpEnabled="true"
automaticFormatSelectionEnabled="true"
maxReceivedMessageSize="2147000000"
/>
</webHttpEndpoint>
</standardEndpoints>
<bindings>
<basicHttpBinding>
<binding name="MyBinding" maxBufferPoolSize="2000000000"
maxBufferSize="2000000000" maxReceivedMessageSize="2000000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
<basicHttpsBinding>
<binding name="MyBinding" maxBufferPoolSize="2000000000"
maxBufferSize="2000000000" maxReceivedMessageSize="2000000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpsBinding>
</bindings>
</system.serviceModel>
</configuration>
But now I get this error: 500 (System.ServiceModel.ServiceActivationException)
Is there any way to resolve this issue?
I found that behaviorConfiguration, bindingConfiguration, <security mode="Transport"> are not set in your code, please make sure to configure them.
You can try setting includeExceptionDetailInFaults to true or configuring tracing to get error details.

Error with WCF webservice moved to Azure VM

I have an old WCF webservice that's been moved to Azure VM.
I can easily access in Azure:
https://wcf/service.svc,
but when I try to post to:
https://wcf/service.svc/json/DoAction
it comes back with an empty response, when I open this in the browser I get 404 error.
Outside of Azure it all works fine, any ideas what can I do to get it to work? I would like to keep it running in VM as there are other items that were moved and work fine.
Here is the part of the web.config file that relates to "/json/" part:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="Service123" behaviorConfiguration="ChallengeBehavior">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="ChallengeMessageEncoding" contract="IService123" behaviorConfiguration="SoapServiceBehavior" />
<endpoint address="/json" binding="webHttpBinding" bindingConfiguration="RestServiceMessageEncoding" contract="IService123" behaviorConfiguration="RestServiceBehavior" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="RestServiceBehavior">
<webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
</behavior>
<behavior name="SoapServiceBehavior">
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="RestServiceMessageEncoding">
<security mode="None">
</security>
</binding>
</webHttpBinding>
<wsHttpBinding>
<binding name="ChallengeMessageEncoding">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
<message clientCredentialType="None" establishSecurityContext="false" negotiateServiceCredential="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
There is no problem the code snippets seem to me. Which version IIS is installed in the Azure VM? Do you have enabled the feature supported for WCF in IIS.
I suspect that the WCF service published on the VM does not work properly. Try to publish a default WCF service application project and browse the self-introduction page.
In addition, for a specific port, you need to enable outbound/inbound permission on the firewall.
VM>>Settings>>Network
Feel free to contact me if there is anything I can help with.
#Abraham, thank you for your answer.
I finally got it working, not sure which part helped but changes I introduced included:
a) Installed additional WCF features (as above) as only 2 were installed
b) Added extra bits to web config (allowing to run URLs with dots in name /Foo.svc/Save )
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<clear />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="/*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
c) Another config to support dots:
<modules runAllManagedModulesForAllRequests="true" />
d) Extended endpoints to support HTTPS as the above started working for HTTP:
<service name="PrivateService" behaviorConfiguration="PrivateBehavior">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="PrivateBehavior" contract="IPrivateService" behaviorConfiguration="SoapBehavior" />
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="PrivateBehaviorSecure" contract="IPrivateService" behaviorConfiguration="SoapBehavior" />
<endpoint address="/json" binding="webHttpBinding" bindingConfiguration="RestSecure" contract="IPrivateServices" behaviorConfiguration="RestBehavior" />
<endpoint address="/json" binding="webHttpBinding" bindingConfiguration="Rest" contract="IPrivateService" behaviorConfiguration="RestBehavior" />
</service>
...
<webHttpBinding>
<binding name="Rest">
<security mode="None">
</security>
</binding>
<binding name="RestSecure">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>

Multiple sites in Azure web app

My Azure web app (example.azurewebsites.net) has one custom domain, applicationhost.config:
<sites>
<site name="example" id="111111111">
<bindings>
<binding protocol="http" bindingInformation="*:80:customdomain.com" />
<binding protocol="https" bindingInformation="*:443:customdomain.com" />
<binding protocol="http" bindingInformation="*:80:example.azurewebsites.net" />
<binding protocol="https" bindingInformation="*:443:example.azurewebsites.net" />
</bindings>
<application path="/" applicationPool="example" preloadEnabled="true">
<virtualDirectory path="/" physicalPath="D:\home\site\wwwroot" />
<virtualDirectory path="/iisnodedebugger" physicalPath="C:\DWASFiles\Sites\example\Temp\iisnode" />
</application>
<traceFailedRequestsLogging enabled="false" customActionsEnabled="true" directory="D:\home\LogFiles" />
<detailedErrorLogging enabled="true" directory="D:\home\LogFiles\DetailedErrors" />
<logFile logSiteId="false" />
</site>
...
</sites>
The custom domain's bindigs are automatically added to the default site (example).
I would like to change it, i would like to create a new site with bindings to the custom domain (customdomain.com).
applicationHost.xdt (created with IIS Manager):
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.applicationHost>
<sites>
<site name="example" xdt:Locator="Match(name)">
<bindings>
<binding bindingInformation="*:443:customdomain.com" xdt:Locator="Match(bindingInformation)" xdt:Transform="Remove" />
<binding bindingInformation="*:80:customdomain.com" xdt:Locator="Match(bindingInformation)" xdt:Transform="Remove" />
</bindings>
</site>
<site name="customdomain" id="222222222" xdt:Transform="InsertAfter(/configuration/system.applicationHost/sites/site[(#name='example')])">
<bindings>
<binding protocol="http" bindingInformation="*:80:customdomain.com" />
<binding protocol="https" bindingInformation="*:443:customdomain.com" />
</bindings>
<application path="/" applicationPool="example" preloadEnabled="true">
<virtualDirectory path="/" physicalPath="D:\home\site\wwwroot2" />
<virtualDirectory path="/iisnodedebugger" physicalPath="C:\DWASFiles\Sites\example\Temp\iisnode" />
</application>
</site>
</sites>
</system.applicationHost>
</configuration>
After restart the transform is successfull.
The problem: it has no effect. The customdomain.com is still served from "D:\home\site\wwwroot" and not "D:\home\site\wwwroot2".
After that i deleted only the bindigs without adding the new site, customdomain still working... After that i deleted the whole site (example), example.azurewebsites.net and customdomain.com still working.
Where am I mistaken? Isn't it possible to manipulate the sites section?
May i ask why are you trying to make your life hard?
Why don't you deploy your 2nd application to a new Web App? You can share the same App Service Plan (same VM) if cost is the essence here.
Every Web App has its own custom domain settings which you can configure visually through the Portal:
https://azure.microsoft.com/en-gb/documentation/articles/web-sites-custom-domain-name/
i did this in the webconfig and it seems to work:
**<rule name="REDIRECT To Site Within a Site" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}"pattern="^www\.SiteWithinSiteName\.com$" />
<add input="{PATH_INFO}" pattern="^/path/SiteWithinSiteRoot/" negate="true" />
</conditions>
<action type="Rewrite" url="\path\SiteWithinSiteRoot\{R:0}" />
</rule>**

Problem with Basic Authentication on Windows Azure RDP

I have hosted one WCF Service on the Azure platform and in web.config enabled basic authentication as per below
<system.serviceModel>
<services>
<service behaviorConfiguration="SimpleServiceBehavior" name="RestService.RestServiceImpl">
<endpoint address="http://localhost/RestWCFDemo/RestServiceImpl.svc" binding="webHttpBinding" bindingConfiguration="secureBasic" contract="RestService.IRestServiceImpl" behaviorConfiguration="HttpEnableBehavior" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="secureBasic">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="HttpEnableBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="SimpleServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
On Azure it is not running. In local I have hosted this service on IIS and Enabled basic authentication only then it will ask for credentials when I will access it from URL, same way I have disabled all authentication methods except basic still I can't run this service what could be the problem? Can anyone suggest a solution?
You can try adding a a proxyCredentialType to your transport:
<transport clientCredentialType="Basic" proxyCredentialType="Basic"/>
I would also set includeExceptionDetailInFaults="true" so you can see the problem better if that doesn't work.

Resources