WCF calling a external service - communication faulted state - wcf

I´m building a winform client using VS 2013. I want to consume a 3party java secure and external (using https with certificate) web service.
I have access to the wsdl. I added a service reference to my .net project referencing the address of the Endpoint and I configured my web.config with wsHttpBinding and transport. ( I have also tried with basicHttpBinding )
In code, I create a client service object and I can see its methods and data types normally.
I have seen that as soon as I create the object, the InnerChannel property is in faulted state mode and I do not understand why.
Show my code in debug mode
The problem is that when calling any of the service object methods, It gives the error:
An unhandled exception of type 'System.InvalidOperationException'
occurred in System.Xml.dll
'System.ServiceModel.CommunicationObjectFaultedException' occurred in
System.ServiceModel.dll
Additional information: The communication object,
System.ServiceModel.ChannelFactory`1
[myproyect.SR.NotificaWsPortType], can not be used for communication
because it is in the Faulted state.
Additional information: There was an error reflecting 'return'.
Can anybody help me?
web.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="NotificaWsBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://<address here>"
binding="wsHttpBinding" bindingConfiguration="NotificaWsBinding"
contract="SR.NotificaWsPortType" name="NotificaWsPort" />
</client>
</system.serviceModel>
</configuration>

I finally found the answer. There was a problem mapping the webservice in .NET because the webservice was developed in java and had a problem whit microsoft technology.
So I spoke with the service providers and they did not have any problems with java but with .net. They changed something in their internals and it worked for me.

Related

basichttpbinding "SOAP-ERROR: Parsing WSDL: Couldn't load from" error [Magento 1.9.3.3]

I'm developing C# application for adding customer data to Magento server. When I try to send customer data, I got this error
System.ServiceModel.CommunicationException: 'Unrecognized message version.'
This is my app.config contents:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="httpBinding" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://127.0.0.1/magento/index.php/api/v2_soap?wsdl=1"
binding="basicHttpBinding" bindingConfiguration="httpBinding"
contract="MagentoService.PortType" name="Port"/>
</client>
</system.serviceModel>
</configuration>
I wonder what wrong with it. Thanks.
UPDATE1: I changed my endpoint address from https://127.0.0.1/magento/index.php/api/v2_soap?wsdl=1 to https://127.0.0.1/magento/index.php/api/v2_soap/index like in Mladen Ilić's referred question. It still don't work and gave me this error:
System.ServiceModel.FaultException: 'SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://127.0.0.1/magento/index.php/api/v2_soap/index/?wsdl=1' : failed to load external entity "https://127.0.0.1/magento/index.php/api/v2_soap/index/?wsdl=1"
More info: my localhost uses self-signed SSL certificate but in my C# code, I already put these code below to bypass SSL check:
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
I think it might be something wrong with my app.config but I can provide my C# code if you interested. Thanks for advance.
UPDATE2: I changed the endpoint address to https://localhost.localdomain/magento/index.php/api/v2_soap/index so I don't need to use SSL bypass anymore. After hours of googling, I found using /api/v2_soap/index instead of api/v2_soap/index/?wsdl=1 is the right thing. My problem is I still got the same error as in UPDATE1.
My coworker and I already fix this issue. It caused by my test environment uses self-signed SSL.
I posted more details at the answer of my coworker's question. Please follow this link below
C# How do I add customer data using SOAP V2 in HTTPS (Magento 1.9.3.3)

Silverlight WCF Service only working on local host

Apologies for the long post but I want to include as much information as possible. So I've been struggling for days now to get my WCF service to work correctly with my silverlight app. I had originally deployed it and everything was running smoothly.
However After i made an update to one of the methods it has not worked since. I use SVN to store my work and even going back to previous versions of the project and redploying it has not helped. Please can someone assist me :(
If I run my silverlight application through VS2012 it works correctly all calls to the service work as required and retrieve the correct information. However if i trigger the same calls once the silverlight app is deployed I receive 1 of the following errors:
An exception occurred during the operation, making the result invalid. Check InnerException for exception details.
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at OrionDashboard.OrionWebService.GetTestDataCompletedEventArgs.get_Result()
at OrionDashboard.MonthlyOverview.OrionWebService_GetTestDataCompleted(Object sender, GetTestDataCompletedEventArgs e)
at OrionDashboard.OrionWebService.OrionWebServiceClient.OnGetTestDataCompleted(Object state)
Or
[Async_ExceptionOccurred] Arguments: Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.51204.0&File=System.dll&Key=Async_ExceptionOccurred at
With the rest of the error corresponding to the onComplete event error of the other error message.
Again this only happens when its deployed to the IIS on the server, And it only started happening after i made the update an redeployed
I've used both WCF Storm and WCF Test Client that was included with VS2012 to test the deployed service over the network and everything is being returned without any issues for all the contracts.
Here is the ServiceReferences.ClinetConfig:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_OrionWebService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:53493/OrionWebService.svc"
binding="customBinding"
bindingConfiguration="CustomBinding_OrionWebService"
contract="OrionWebService.OrionWebService"
name="CustomBinding_OrionWebService" />
</client>
</system.serviceModel>
I have made no changes to this at all from what was auto generated when i referenced the service project. I thought it may have been this line: "http://localhost:53493/OrionWebService.svc"
because in fiddler i receive the following errors on the crossdomain.xml and the clientaccesspolicy.xml
[Fiddler] The socket connection to localhost failed.
ErrorCode: 10061.
No connection could be made because the target machine actively refused it [::1]:53493
however when i changed the xap to a zip file and modified the ServiceReference.ClientConfig to point to the same service address as would work if you wanted to check your service e.g. "http://ServerName/OrionDashboard/OrionWebService.svc" I still get the same error from silverlight and then get a 404 error from the two files.
Here is the web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true"
targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="OrionDashboard.Web.OrionWebService.customBinding0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="OrionDashboard.Web.OrionWebService">
<endpoint address=""
binding="customBinding"
bindingConfiguration="OrionDashboard.Web.OrionWebService.customBinding0"
contract="OrionDashboard.Web.OrionWebService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
As with the ServiceReference, the web.config too was left alone because I dont really understand what most of it means. But I left it as is when I first deployed the silverlight app and as mentioned it worked fine then.
I don't believe its a DB issue since it runs locally without any issues and the service responds with the correct data from the deployed service as well.
The service seems to be working fine, no issues reported from either the WCF Test Client or WCF Storm app
In VS2012 when publishing the wcf service it doesn't separate the service from the client and it doesn't create the crossdomain.xml or clientaccesspolicy.xml so I manually added those after publishing it. Not sure if that could possibly be the cause?
I'm completely lost and every work around I've found so far has not worked for me. Please can someone at least point me in the right direction?

WP7 + WCF Service: There was no endpoint listening at (URL) that could accept the message

I'm trying to develop a Windows Phone application that uses a WCF Service. I'm doing it as decribed here:
http://www.c-sharpcorner.com/UploadFile/raj1979/5280/
(of course I use my own tables from the DB). The problem is:
I'm debugging the Class Library project containing the WCF service (to see if some of its methods are invoked properly)
after the method returns an entity I see the error: There was no endpoint listening at http://localhost:1708/Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The InnerException is The remote server returned an error: NotFound.
the ServiceReferences.ClientConfig in the Windows Phone application:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1708/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
I don't know how to solve it. Any ideas ? I tried many answers from that site but none worked
What about Silverlight-enabled WCF service on the server side? It it based on CustomBinding instead of basicHttpBinding.
You must change in ServiceReferences.ClientConfig in your Windows Phone Emulator endpoint address from localhost to
yourComputerName. Thats all:) It works

WCF call with windows authentication

We have a system where the users access a web server, the web server then calls a WCF service.
We would like the call to the WCF service to be made in the security context of the windows identity of the application pool on the web server.
What is the best way to do this? Can it be done purely through configuration in the web.config file.
Thanks
Shiraz
Yes, you should be able to do this, all in config:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="WinAuth" mode="Transport">
<transport clientCredentialType="Windows" />
<bindings>
</netTcpBinding>
</bindings>
</system.serviceModel>
Of course, depending on your binding, you'd have to use a different tag under the <bindings> parent node - and of course, not all bindings support all security modes.....
In your endpoint, use the appropriate binding and then just reference this config:
<endpoint name="WCFService" address="......."
binding="netTcpBinding"
bindingConfiguration="WinAuth"
contract="......" />
That should do it! And of course, if you need message security instead of transport security, you can do that, too.
In your WCF service method, you can check to see whether or not the Windows credentials have been sent over, and what they are, by checking:
ServiceSecurityContext.Current.WindowsIdentity
This will be NULL if you don't have a Windows caller, otherwise it will show who called you.
Marc

Why doesn't WSDL from WCF service include the custom binding for the STS?

I'm writing a C# WCF service that publishes an endpoint using a WSHttpFederationBinding. We have our own security token server providing tokens, for which callers need to use a custom binding.
This is all working fine for a C# client I've written: this has a custom binding in its app.config like so:
<bindings>
<customBinding>
<binding name="CustBind">
<security authenticationMode="UserNameForCertificate" requireDerivedKeys="true"
messageProtectionOrder="SignBeforeEncryptAndEncryptSignature"
requireSecurityContextCancellation="false"
requireSignatureConfirmation="false">
<secureConversationBootstrap/>
</security>
<httpTransport/>
</binding>
</customBinding>
<wsFederationHttpBinding>
<binding name="FedBind">
<security>
<message issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1"
negotiateServiceCredential="false">
<issuer address="http://STSHost/MySTS" binding="customBinding"
bindingConfiguration="CustBind">
<identity>
<certificateReference x509FindType="FindBySubjectName" findValue="localhost"/>
</identity>
</issuer>
</message>
</security>
</binding>
</wsFederationHttpBinding>
</bindings>
However, what I want is for users to be able to generate their own clients in whatever language they want, just given the WSDL that the WCF service publishes. The problem with this is that when I try such a thing with Developer Studio's "Add Service Reference" functionality, the resulting client doesn't work.
The reason it doesn't work is because the generated client's app.config is clearly wrong: while the STS is there in the "issuer" element, there's no sign of the custom binding. Looking at the WSDL this isn't too surprising, as there's no mention of anything there other than the issuer address.
Is there any way to get WCF to add something to the WSDL to describe this situation? My server's app.config bindings look okay to me: the "issuer" element is exactly the same as for the working client, including the address and details of the custom binding. Does anyone know why WCF seems to be ignoring this when generating the WSDL?