I'm trying to call web service provided by WSDL file.
after adding the WSDL as service referece and point to location of WSDL file on my computer.
using code i tried to assign a certificate to the web service like this:
NeqatyService.NeqatyWSAPIPortTypeClient mPortType = new NeqatyWSAPIPortTypeClient();
Byte[] rawData = File.ReadAllBytes(#"c:\cert.p12");
String cert64 = Convert.ToBase64String(rawData);
X509Certificate2 certificates = new X509Certificate2(rawData, "pass", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.UserKeySet);
mPortType.ClientCredentials.ClientCertificate.Certificate = certificates;
the debugger raise an error on this line:
mPortType.ClientCredentials.ClientCertificate.Certificate = certificates;
telling that:
Object is read-only
I want to notice that, i used to call the web service using SOAPUI
providing the certificate and the password and it worked.
can anybody help me with this.
Try modifying the value of messageEncoding to "Mtom" in the binding configuration. Here is an example of a configuration that I used recently. I was getting that error when the value was set to "Text."
<binding name="AWDProcessingServiceBinding" closeTimeout="00:01:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="655360" maxBufferPoolSize="524288" maxReceivedMessageSize="655360"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Certificate" proxyCredentialType="Basic"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
Related
I am using WCF service. The problem I have is its starts using double memory.
I am using HTTPS binding
<wsHttpBinding>
<binding name="secureHttpBinding" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="Transport" >
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
<endpoint address="https://localhost/test.svc"
binding="wsHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="IWcfContract"
name="SecureBasicHttpBinding_WcfContract">
Here is the code I am using to upload
using (Stream fileStream = File.OpenRead(logsZipFullPath))
{
// Call web server
UploadFileResponse response = _webServiceHelper.UploadFile(fileStream, currentDate, ".zip", string.Empty);
fileStream.Close();
}
Here is my model
[MessageContract]
public class UploadFileRequest : IDisposable
{
[MessageBodyMember(Order = 1)]
public Stream FileByteStream;
[MessageHeader(MustUnderstand = true)]
public string FileDescription;
}
My zip file is of 80MB.
The problem I have is at the start of the service its using 26mb which is quite fine. At the first call it uses 136MB after call completes it goes down to 26mb. which is also fine. after the second call to upload it starts using 346MB
which again gets down to 26mb after service call. My question is why it is using 346MB when the file is of only 80MB? My GC and disponse has been called correctly. But, is this normal behaviour or I am missing anything?
finally found a work around for this. According to this post
wsHttpBinding is the full-blown binding, which supports a ton of WS-*
features and standards - it has lots more security features, you can
use sessionful connections, you can use reliable messaging, you can
use transactional control - just a lot more stuff, but wsHttpBinding
is also a lot *heavier" and adds a lot of overhead to your messages as
they travel across the network
I think this is the main reason why the memory usage is high. Our requirement was to use the HTTPS certificate and we are able to use this with basicHttpBinding. SO, I changed my settings like this
<basicHttpBinding>
<binding name="BasicHttpBinding_WcfContract" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="Transport"> <-- this is the main change
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
Note: I changed security mode none to transport to support https.
Now, everything works without the issue.
Two possible things which causes memory issues.
wsHttpBinding overheads
Stream mode is not supported in wsHttpBinding
i'm currently working on a client/server program which is using wshttpdualbinding for communication in vs with c#. So i'm calling webservices over this binding from the server.
Everything worked fine, but in the last days i'm encountering the following problem: if i call a service from the server, the client just stops working and stops reacting. Nothing gets send from the client.
I can't post much, because it is a big project, but i'll try to post the best snippets:
binding:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_AuthenticationService" closeTimeout="03:10:00"
openTimeout="03:10:00" receiveTimeout="03:10:00" sendTimeout="03:10:00"
bypassProxyOnLocal="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
useDefaultWebProxy="true" allowCookies="false" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_Service" closeTimeout="03:10:00"
openTimeout="03:10:00" receiveTimeout="03:10:00" sendTimeout="03:10:00"
bypassProxyOnLocal="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
useDefaultWebProxy="true" messageEncoding="Text" textEncoding="utf-8" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</wsDualHttpBinding>
</bindings>
problem causing code:
Clusterrationalemapping cr = new Clusterrationalemapping
{
Textbricks = rationale,
Cluster = cluster,
Project = CurrentProject
};
var clusterrationaleId = 0;
if (cluster.AddClusterRationaleMapping(cr))
{
clusterrationaleId = _service.SaveItem(cr);
cr.Id = clusterrationaleId;
if(rationale.Clusterrationalemappings == null) rationale.Clusterrationalemappings = new List<Clusterrationalemapping>();
rationale.Clusterrationalemappings.Add(cr);
}
A function gets called which creates a new clusterrationalemapping for a specific cluster. The rational and CurrentProject variables are always the same. just cluster is different.
Most of the time everything works and service.SaveItem returns the new Id as expected. But for one special cluster it is not working. service.SaveItem just stops and freezes the tool until i get some exception (server did not respond in time/gave no answer).
I'm sure that the wsDualHttpBinding is set correctly. If i comment out the line Project = CurrentProject and replace it with Project = new Project(); everything works fine for this cluster again.
So it looks like clusterrationalmapping might get too big for sending. But the exception is not saying that. And i got it from the server - from that direction it worked.
I used Microsoft Service Trace Viewer for debugging purpose and i can see there, that it instantly throws an exception that the endpoint could not be reached. So i'm pretty sure that the service dies when serializing the object.
Is there any way to debug into the service to see when exactly, or better why, it fails?
Thanks in advance for your help.
Since I have not been able to find a solution - I still think that there has been a problem with the serializer and a too big/nested class, i changed the binding to nettcp and it is working now.
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.
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#.
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.