Custom Message Encoder WCF - invalid signature - c#

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.

Related

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.

C# calling Magento soap service endpoint binding not using HTTP?

I am using C# to call Magento SOAP API, and we have until now using HTTP to call this service. Now we have install SSL to our website so soap is no longer available from HTTP.
So for change I have modify service in my Visual Studio project and my App.config have change into:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Binding" maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000" >
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://www.ourwebstore.com/api/v2_soap/" binding="basicHttpBinding"
bindingConfiguration="Binding" contract="ServiceReference.PortType"
name="Port" />
</client>
</system.serviceModel>
</configuration>
Before modifying service request instead https was HTTP. And with HTTP works fine and fast. But when we upgrade into https, problem was, that our call services are slower, and randomly (the process is sometimes finished sometime not) I get an error (when before use of HTTP this error did not show up). Error is:
Unhandled Exception: System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to https://www.ourwebstore.com/api/v2_soap/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
Any idea where is a problem?

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: Identical config file on server and client side?

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.

Call Sharepoint Web Service over SSL with Silverlight

I have a Silverlight 5 app that gets some data from a couple Sharepoint lists. It was all working correctly, then we set up the site to allow SSL and I tried to update the service reference to call the webservice using https. It updated the client config binding to use security mode Transport. But when it calls the service it's giving an error:
System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI 'https://devlpadmin.thelittlegym.com/_vti_bin/Lists.asmx'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details. ---> System.Security.SecurityException ---> System.Security.SecurityException: Security error.
Does anyone know what the problem is or how to get more info than "Security error."?
I've gone through so many different combinations of things that I'm not sure exactly what has happened when, but it's now working. I think originally the site/service was having some weird problem that prompted me to try to manually configure Silverlight to pass NTLM transport credentials. In doing so, I might have created an invalid config file causing the error. The configuration that is working is:
<bindings>
<basicHttpBinding>
<binding name="ListsSoap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://devadmin.mydomain.com/_vti_bin/Lists.asmx"
binding="basicHttpBinding" bindingConfiguration="ListsSoap"
contract="SPListsService.ListsSoap" name="ListsSoap" />
</client>
So if you're having this error and not making a cross-domain call, suspect some kind underlying service error. If you're not using Silverlight, you can enable tracing to track down the error. If you are using Silverlight, I still don't know what can be done to narrow it down, but be aware that Silverlight only supports a fragment of the configuration options that a normal .net WCF client does.

Categories