WCF: Identical config file on server and client side? - c#

My WCF service hang randomly. when I try to debug using Microsoft Service Trace Viewer I found out I was getting
The socket connection was aborted. This could be caused by an error
processing your message or a receive timeout being exceeded by the
remote host, or an underlying network resource issue. Local socket
timeout was '00:01:00'.
Therefore I change the "receiveTimeout" in the Net pipe binding section (server side) like this.
Server side
<netNamedPipeBinding>
<binding name="myPipeBinding"
receiveTimeout="24:0:0">
</binding>
</netNamedPipeBinding>
And then I try to update the config file of the client using the Visual Studio 2013 "Update Service Reference". It give me the new App.config in the client side like this.
<bindings>
<netNamedPipeBinding>
<binding name="NamedPipedService" />
</netNamedPipeBinding>
</bindings>
<client>
<endpoint address="net.pipe://localhost/Server" binding="netNamedPipeBinding"
bindingConfiguration="NamedPipedService" contract="WCFService.IServer"
name="NamedPipedService">
<identity>
<userPrincipalName value="Server\MyComputer" />
</identity>
</endpoint>
</client>
I thought everything work but my service crash again with the same error. So I thought "receiveTimeout" section of the "netNamedPipeBinding" should also be added in the client's App.config file. My question is
Is the error I am getting due to default timeout value of Net pipe binding?
Should I set the receiveTimeout value (server side) ?
Do I also need to change the App.config file in the client side for the changes to take effect? Since updating by Visual Studio 2013 does not add the receiveTimeout section.

Related

Custom Message Encoder WCF - invalid signature

I tried to use the same service as #Misiu like in:
Custom MessageEncoder add attributes to message without modifying structure
I know that post has 3 years but I hope someone knows the answer.
I'm facing the same problem.
System.ServiceModel.CommunicationException: An error occurred while making the HTTP request to https://dz3.swd.zbp.pl/broker3/services/QueryDz. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
I don’t know the ins and outs of the issue. The above error mainly indicates that the service certificate is not properly configured when we make the service work over HTTPS, as the error mentioned. In order to make WCF service work over HTTPS, we should add a service endpoint with transport security mode.
<services>
<service name="WcfService3.Service1">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="mybinding" contract="WcfService3.IService1" behaviorConfiguration="mybeh"></endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="mybinding">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
Subsequently, if the WCF project is hosted in IIS, we should add an https binding and bind a certificate in the IIS site binding module.
If the service is self-hosted, we could bind a certificate to a specific port by using the following command.
netsh http add sslcert ipport=0.0.0.0:8000 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00112233-4455-6677-8899-AABBCCDDEEFF}
Please refer to the below documentation.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-a-port-with-an-ssl-certificate
Feel free to let me know if there is anything I can help with.

To involve SharePoint WCF Service with SSL-Certificate from Client laptop failed

My testing environment is:
1* Server :: SharePoint Site with WCF Service (in the ISAPI folder) and we configured the SSL and Cert on it.
1* Client :: Windows 10 with one Console Application to involve the WCF service
Testing (1) :all programs (WCF Service and Console Application) on the SharePoint Server
I created a Console application to invoke the WCF Service in SharePoint. Meantime, the Console application and WCF are on the same server. the outcome is everything works properly. It is successful to upload file into a Document Library.
Testing (2) :to simulate my client environment:
1* SharePoint :WCF Service
1* Windows 10 :Console application
the outcome failed and I got the error message:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'
To be honest, I stuck here for a while. I also list out a portion of my source code for someone of experience to look at. I also posted some sample code and web.config in here.
Updated.
If we enable NTLM authentication, we have to enable the windows authentication.
Then when calling the service, we need to provide windows credential.
//it will use the binding and service endpoint address in the system.servicemode section.
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
//windows account on the server.
client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
client.ClientCredentials.Windows.ClientCredential.Password = "abcd1234!";
try
{
Console.WriteLine(client.SayHello());
}
catch (Exception)
{
throw;
}
Auto-generated configuration.
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService">
<security mode="Transport">
<transport clientCredentialType="Ntlm" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://vabqia969vm:21011/" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService" contract="ServiceReference1.IService"
name="WSHttpBinding_IService">
<identity>
<userPrincipalName value="VABQIA969VM\Administrator" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Feel free to let me know if the problem still exists.

After deploy: There was no endpoint listening at ipaddress/service.asmx that could accept the message

My asp.net MVC application calls a wcf web service, it works fine on my machine, but when I publish it on our own staging server I get the error:
Inner Exception: No connection could be made because the target
machine actively refused it IPADDRESS:8080
Message: There was no endpoint listening at
http://IPADDRESS:8080/SERVICE.asmx that could accept the
message. This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details.
This is the web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SERVICEWebIntegrationSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://IPADDRESS:8080/SERVICEwebintegration.asmx" binding="basicHttpBinding" bindingConfiguration="SERVICEWebIntegrationSoap" contract="SERVICEServiceReference.SERVICEWebIntegrationSoap" name="SERVICEWebIntegrationSoap" />
</client>
</system.serviceModel>
How I said it works on local as well as the service responds well if I use the url http://IPADDRESS:8080/SERVICEwebintegration.asmx in the browser.
Any idea?

WCF MSMQ - SRMP on a different port

I have an application that pushes messages to a WCF endpoint via an MSMQ.
In dev, it works well when using the MSMQ protocol, but in production I need to do a network hop. I need to set this up so the queue pushes to the WCF endpoint over HTTP on a specific port (22200).
I thought this would work with SRMP, but it is not working. My outgoing MSMQ hangs with a message saying "Waiting to connect".
I've checked and I have access to the URL on the correct port.
How do I work out what the issue is?
Below is my client application configuration:
<bindings>
<netMsmqBinding>
<binding name="NetMsmqBinding_IMyProjectReceiverService" exactlyOnce="false" timeToLive="00:01:00" queueTransferProtocol="SrmpSecure">
<security mode="None" />
</binding>
</netMsmqBinding>
</bindings>
<client>
<endpoint
address="net.msmq://exampleuri.com:22200/private/MyProject.Receiver/v1/MyProjectReceiverService.svc"
contract="IMyProjectReceiverService"
binding="netMsmqBinding"
bindingConfiguration="NetMsmqBinding_IMyProjectReceiverService"
name="NetMsmqBinding_IMyProjectReceiverService" />
</client>

Web Reference works, but A Service Reference complains about Soap version

I have to connect to a legacy web service.
In visual studio, if I do a Add Service Reference, then enter the url of the WSDL file on server. My service shows up, and I write the code against it. But when I run the code I get this error:
System.ServiceModel.CommunicationException: The envelope version of
the incoming message (Soap12
(http://www.w3.org/2003/05/soap-envelope)) does not match that of the
encoder (Soap11 (http://schemas.xmlsoap.org/soap/envelope/)). Make
sure the binding is configured with the same version as the expected
messages.
My app.config looks like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="LoginServiceSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://server/Service.asmx" binding="basicHttpBinding"
bindingConfiguration="LoginServiceSoap" contract="Stuff.Login.LoginServiceSoap"
name="LoginServiceSoap" />
</client>
</system.serviceModel>
However, I am able to communicate with the service fine, if I add a 'Web Reference'. But my understanding is that I am supposed to use Service References now, instead of WebReferences. I am assuming I have something wrong in my above config.
Or am I forced to use a Web Reference, because of the type of service I am connecting to?
Sheamus,
You could (theoretically) add the version number to the binding definition.
envelopeVersion="None/Soap11/Soap12"
With, of course, the right value for your service.
So it would look more like:
<basicHttpBinding>
<binding name="LoginServiceSoap"
envelopeVersion="Soap12" />
</basicHttpBinding>
Hope this helps you do things your way.

Categories