Java WebService with .NET issue. Results different with scvutil /wrapped and not - c#

I'm using a well known vendor's API with a WSDL link1, link2 (click wait to download):
The above mentioned documentation wants me to create an Authentication request packet like this:
<soapenv:Envelope xmlns:soapenv=‖http://schemas.xmlsoap.org/soap/envelope/‖
xmlns:web=‖http://UltraWebServiceLocation/‖>
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand=‖1‖ xmlns:wsse=‖http://docs.oasisopen.
org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd‖>
<wsse:UsernameToken wsu:Id=‖UsernameToken-16318950‖ xmlns:wsu=‖http://docs.oasisopen.
org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd‖>
<wsse:Username>bwooster</wsse:Username>
<wsse:Password Type=‖http://docs.oasis-open.org/wss/2004/01/oasis-200401-wssusername-
token-profile-1.0#PasswordText‖>**********</wsse:Password>
<wsse:Nonce>QTvkiqEFK7uJuOssMndagA==</wsse:Nonce>
<wsu:Created>2009-04-14T21:20:57.108Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
My client binding looks like this; and am using a service reference instead of a web reference.
UltraDNS.UltraDNS1Client client = new UltraDNS.UltraDNS1Client();
client.ClientCredentials.UserName.UserName = "user";
client.ClientCredentials.UserName.Password = "pass";
var results = client.getResourceRecordsOfZone("domain.com",1);
// Throws InvalidOperationException: There was an error reflecting 'UltraWSException'.
// Detail:
//{"Namespace='http://webservice.api.ultra.neustar.com/v01/' is not supported with rpc\\literal SOAP. The wrapper element has to be unqualified."}
The web config looks like this
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="UltraDNS1Binding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://ultra-api.ultradns.com:80/UltraDNS_WS/v01"
binding="basicHttpBinding" bindingConfiguration="UltraDNS1Binding"
contract="UltraDNSService.UltraDNS1" name="UltraWebServiceV01Port" />
</client>
</system.serviceModel>
When I use SVCUtil to generate the proxy class with the /wrap parameter I get the following error:
{"The top XML element 'result' from namespace '' references distinct types System.String and ZoneInfoData[]. Use XML attributes to specify another XML name or namespace for the element or types."}

You appear to have used "Add Web Reference". Please use "Add Service Reference" instead.
Then see Programming WCF Security.
The service is sending you a fault of some kind (UltraWSException). WCF is having trouble deserializing it, but if you turn on message tracing, you may be able to see what the error is, and fix it.

Related

TLS for securing acces to web services

I need to send the combination (login name / User Password) from my web application to a web service that autenticate all employees in all the companie's programs. But what is happening rigth now is plain text going throught the wire. I was asked to use TLS (not SSL3) in order to encrypt the combination for decent security (asp.net 4.0 Framework, c#).
The problem is I don't even know where to start, everywhere I look for similar questions, I see peoples that are arleady very close to there goal, only needing one last line of code to confirm the certificate or one last little configuration to allow the "handshake" process.
The way I am accessing my web services seems TOO SIMPLE, maybe I have to start all over from the begining, that's is why I want to ask poeple first. Here is how i call the web service's fonctions :
In the Web.Config :
//Binding
<binding name="BasicHttpBinding_ICommun1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
//Declaring EndPoint
<endpoint address="http://CannotTellYouThat.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICommun1"
contract="NameOfTheService.ICommun" name="BasicHttpBinding_ICommun1" />
In the C# class, I only need this :
public NameOfTheService.Utilisateur login(string ip, string nomUtilisateur, string userPass)
{
NameOfTheService.CommunClient instance = new NameOfTheService.CommunClient();
return instance.Authentifier(ip, nomUtilisateur, userPass, AuthentificationServices.SystemeEnum.AppName);
}
It returns a User (Utilisateur) with all the informations needed. This looks like I have to remove the web.Config binding and do all that in the C#. Any kind of help or advice would be welcome. Thanks.

C# WCF - net.tcp cannot find endpoint

I'm getting the following error message when trying to implement net.tcp WCF in C#:
"Could not find default endpoint element that references contract 'EventInterfaceService.IEventInterface'
in the ServiceModel client configuration section. This might be because no configuration file was found for your application,
or because no endpoint element matching this contract could be found in the client element."
On my client side I have the following code:
private void Initialize(string sInterfaceUrl, string sUserParticipantName)
{
EventInterfaceCallbackSink _callbackSink;
InstanceContext _instanceContext;
EndpointAddressBuilder _endpointAddressBuilder;
_callbackSink = new EventInterfaceCallbackSink();
_instanceContext = new InstanceContext(_callbackSink);
eventInterfaceClient = new EventInterfaceClient(_instanceContext); //Exception gets thrown here
EndpointIdentity edi = EndpointIdentity.CreateUpnIdentity(sUserParticipantName);
var endpointAddress = eventInterfaceClient.Endpoint.Address;
EndpointAddressBuilder newEndpointAddress = new EndpointAddressBuilder(endpointAddress);
newEndpointAddress.Uri = new Uri(sInterfaceUrl);
newEndpointAddress.Identity = edi;
eventInterfaceClient.Endpoint.Address = newEndpointAddress.ToEndpointAddress();
}
As you can see I get the EndPointAddress as sInterfaceUrl and the UserParticipantName as sUserParticipantName.
For the app.config I have the following:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_Interface" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="Infinite" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
textEncoding="utf-8" useDefaultWebProxy="true" messageEncoding="Text">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IEventInterface"/>
</netTcpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/HTTPWCF/" binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_Interface" contract="InterfaceService.IInterface"
name="basicHttpBinding_Interface" />
<endpoint address="net.tcp://localhost:8733/NETTCPWCF/"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IEventInterface"
contract="EventInterfaceService.IEventInterface" name="NetTcpBinding_IEventInterface">
</endpoint>
</client>
</system.serviceModel>
When running this code in a stand-alone client (not the actual application) it works. I can't seem to find out what's wrong. Any tips would be great!
Thanks.
Edit: Is there any way configuring this purely at runtime, so I won't need the app.config? Regarding the comments below, config file may not be found or wrong one is being used.
Your comment mentioned that you are putting your app.config stuff into a class library. This won't be read. The app.config of the executing assembly gets read instead (or the web.config since this is ASP). You will need to add your relevant config info to the config file of the executing assembly (your ASP project).
Alternatively, you could use the static ConfigurationManager class to read in your specific app.config settings:
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

Magento API in C# - throwing content type exception

When i am trying to use the Magento Product download webservice call in my C# application.
I am getting some content type Mismatch error. Could you please help me?
Here is my code:
using (Mage_Api_Model_Server_V2_HandlerPortTypeClient proxy = new Mage_Api_Model_Server_V2_HandlerPortTypeClient())
{
string sessionId = proxy.login("stalin", "12345678");
customerCustomerEntity[] customers = proxy.customerCustomerList(sessionId, new filters());
foreach (customerCustomerEntity customer in customers)
{
Console.WriteLine(String.Format("{0}. {1} {2}", customer.customer_id, customer.firstname, customer.lastname));
}
proxy.endSession(sessionId);
}
Here is my Web config details:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Mage_Api_Model_Server_V2_HandlerBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="9999999" maxBufferPoolSize="524288" maxReceivedMessageSize="9999999" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://<my server ip>/magento-1.7.0.2/index.php/api/v2_soap/index/" binding="basicHttpBinding" bindingConfiguration="Mage_Api_Model_Server_V2_HandlerBinding" contract="VPMagento.Mage_Api_Model_Server_V2_HandlerPortType" name="Mage_Api_Model_Server_V2_HandlerPort"/>
</client>
And the error message is:
The content type text/html of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 361 bytes of the response were: '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>0</faultcode>
<faultstring>SOAP extension is not loaded.</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'.
Any solution for this issue please?.
Otherwise let me know how to use the Magento API in C#.

Getting started with Paypal Adaptive Payments in C# SOAP

I'm trying to start with Adaptive Payments by Paypal using SOAP interface.
When adding service reference to https://svcs.sandbox.paypal.com/AdaptivePayments?WSDL the following warning is shown by Visual Studio:
Custom tool warning: Cannot import wsdl:binding
Detail: The WSDL binding named AdaptivePaymentsSOAP11Binding is not valid because no match for operation CancelPreapproval was found in the corresponding portType definition.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://svcs.paypal.com/services']/wsdl:binding[#name='AdaptivePaymentsSOAP11Binding'] C:\cproj\daemon\Service References\PaypalSandboxApi\Reference.svcmap 1 1 daemon
Discarding this message, the reference added successfully.
In order to perform a transaction, I try to create the client:
var client = new PaypalSandboxApi.AdaptivePaymentsPortTypeClient()
This throws InvalidOperationException:
Could not find default endpoint element that references contract 'PaypalSandboxApi.AdaptivePaymentsPortType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Am I missing something?
Should I use missing AdaptivePaymentsSOAP11Binding and not AdaptivePaymentsPortTypeClient?
It looks like importing this WSDL doesn't generate the servicemodel config. I kludged one together like this (and updated the relevant classname to match yours, so you can copy/paste):
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="PaypalAdaptivePayBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1048576" maxBufferPoolSize="1048576" maxReceivedMessageSize="1048576" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="65536" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://svcs.sandbox.paypal.com/AdaptivePayments"
binding="basicHttpBinding" bindingConfiguration="PaypalAdaptivePayBinding"
contract="PaypalSandboxApi.AdaptivePaymentsPortType"
name="PaypalAdaptivePay" />
</client>

InvalidOperationException when using soap client

I've added as wsdl file using the add servece reference dialog in vs2008.
MyService serviceproxy = new MyService();
When I instantiate the service proxy, I get an InvalidOperationException with the following text (translated from german):
Could not find default endpoint
element to the contract
"ServiceName.ServiceInterface" in the
service model refers client
configuration section. This may be
because: The application configuration
file was not found or not an endpoint
in the client element item is found,
which corresponded to this contract.
Where servicename is the name I give the service when I add it in vs2008 and ServiceInterface the interface which is automatically generated for it.
EDIT
here is what's in my app.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyServiceBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
You need something like this in your config:
<client>
<endpoint binding="basicHttpBinding"
bindingConfiguration="MyServiceBinding" contract="ServiceName.ServiceInterface"
name="MyServiceEndpoint">
</endpoint>
</client>
inside your tag
I just read your comment.
So Removed the address from the endpoint config.
You can choose to specify the endpoint completely in your code or just the address like this:
MyServiceClient proxy = new MyServiceClient();
proxy.Endpoint.Address = new EndpointAddress ("http://addressto your service"); //<-- address
Check your config file - web.config if you're in a ASP.NET web app or web site, app.config if it's a Winforms or console app.
There ought to be some config for your WCF service in there - anything below <system.serviceModel> would be fine. If not - add the necessary info to your config!
OK, so if you want to specify your endpoint URL in code, you need to do this when you instantiate your client proxy class - otherwise, it'll go look in config. Using this code snippet, you'll be using the http binding configuration settings from app.config, and specify the URL separately, in code:
BasicHttpBinding binding = new BasicHttpBinding("MyServiceBinding");
EndpointAddress address = new EndpointAddress(new Uri("http://localhost:8888/YourService"));
MyService serviceproxy = new MyService(binding, address);
That way, the basicHttpBinding object will read the settings from the config under the bindings with a name=MyServiceBinding.
Edit:
Sorry, my first answer was wrong. For the client you need:
ChannelFactory<Interface> factory = new ChannelFactory< YourServiceInterface >(new basicHttpBinding(), new EndpointAddress(new Uri("http://localhost:8888/YourService")));
YourServiceInterface proxy = factory.CreateChannel();

Categories