WCF service giving no response with TCP and Http protocols from azure - 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;
}
}

Related

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>

MONO WCF Self-Hosted Service Pair getting Connection reset by peer when using net.tcp

I Have 2 WCF-Self-Hosted Aplications done with mono. One is on Windows 8 and the other is on Ubuntu Linux. When i put both applications under Windows8 or Ubuntu, they communicate fine. When i put them apart, one in windows and one in Linux, i get a "System.IO.IOException: Read Failure ---> System.Net.Sockets.SocketException: Connection reset by peer.
I've read every single page i could find about this error with no luck on how to fix it.
i attack bellow the app.config of both apps. They communicate using net.TCP and the svcutil worked fine pulling the metadata.
CLIENT App.config (This one tries to pull data from the other, and when he collects the data, calls a 3rd Not-Implemented Yet service. )
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IMiServicio" >
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://192.168.1.101:8090/ProyectoDistribuidoTCP"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IMiServicio"
contract="IMiServicio" name="NetTcpBinding_IMiServicio">
<identity>
<userPrincipalName value="ALEXMAINGEAR\Alex" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
SERVER App.config (this one serves the data to the second service)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<services>
<service name="ProyectoDistribuido.MiServicio" behaviorConfiguration="metadataSupport">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ProyectoDistribuidoHTTP"/>
<add baseAddress="net.tcp://localhost:8090/ProyectoDistribuidoTCP"/>
</baseAddresses>
</host>
<endpoint binding="basicHttpBinding"
contract="ProyectoDistribuido.IMiServicio"/>
<endpoint binding="netTcpBinding"
contract="ProyectoDistribuido.IMiServicio"/>
<endpoint address= "tcpmex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding">
<security mode= "None"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="metadataSupport">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I know this post is rather old, but I recently found myself in a similar situation and there is still very little information on this online.
In my case, the problem was that the net.tcp binding defaults to using Windows Authentication based security.
This is fine when both services are in windows, but when one is hosted in Linux it doesn't have access to this (unless you've configured it) and the connection fails.
The error message definitely leaves something to be desired!
Here's the config I used to disable security (as I don't need it yet) with net.tcp binding.
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="bindingConfig">
<security mode="None">
<transport clientCredentialType="None" protectionLevel="EncryptAndSign" />
<message clientCredentialType="None" algorithmSuite="Default" />
</security>
</binding>
</netTcpBinding>
</bindings>
<!-- remainder of system.serviceModel -->
Note: You need to configure your service client to disable security as well. In my case, my client didn't have a .config file so I had to do it in code:
var binding = new NetTcpBinding()
{
MaxBufferSize = int.MaxValue,
ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max,
MaxReceivedMessageSize = int.MaxValue,
Security = new NetTcpSecurity()
{
Message = new MessageSecurityOverTcp()
{
ClientCredentialType = MessageCredentialType.None
},
Transport = new TcpTransportSecurity()
{
ClientCredentialType = TcpClientCredentialType.None
},
Mode = SecurityMode.None
}
};

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.

SharePoint, WCF and Anonymous Access

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

Resources