Send GZIP compress the request to web service via WCF - c#

There is similar question is available here
GZIP compress the request to a remote web service via WCF
When I have implemented solution provided by expert
i.e. WCF client endpoint compression
here is my web.config file code
<bindings>
<customBinding>
<binding name="NAME" >
<binaryMessageEncoding compressionFormat="GZip"/>
<httpsTransport/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="MYENDPOINTURL"
binding="customBinding" bindingConfiguration="NAME"
contract="ICONTRACT" name="BulkRequestTransmitterPort" />
</client>
below is error I am getting
Error: The content type text/xml;charset=utf-8 of the response message does not match the content type of the binding (application/soap+msbin1+gzip). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 807 bytes of the response were: '
soapenv:Client
The request message must be sent using HTTP compression (RFC 1952 - GZIP).
TPE1112
'
Can someone please tell me where I am doing wrong?``
Thanks

Related

How to consume a soap web-service in c# and pass XML in request?

I need your help to find the best way to call a soap web-service in c# ?
I know using the web-service reference feature in c# is a good one.
I tried using it and it did not work ?
Here is the xml that I want to post
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://temenos.com/CUSTDETS">
<soapenv:Header/>
<soapenv:Body>
<cus:EDBCUSTDETS>
<WebRequestCommon>
<!--Optional:-->
<company></company>
<password></password>
<userName></userName>
</WebRequestCommon>
<EDBCUSTDETSType>
<!--Zero or more repetitions:-->
<enquiryInputCollection>
<columnName></columnName>
<criteriaValue></criteriaValue>
<operand>EQ</operand>
</enquiryInputCollection>
</EDBCUSTDETSType>
</cus:EDBCUSTDETS>
</soapenv:Body>
</soapenv:Envelope>
After adding the reference for the WSDL in the service references folder, I named it as ServiceReference1.
Now I Can see in my code :
How to achieve this request ?
how can I add company, password and user Name and the enquiryInputCollection parameters ?
Is there any best practice for achieving this ?
Thanks.
If you have successfully generated proxy classed from WSDL, then you should be good to go. I assume you should have been provided web service documentation for consuming them.
Look for service client classes to begin with.
eg:
var client = new ServiceReference1Client();
client. ? //(should list Methods and you can find Types of Paramaters to build them.)
If you check in web.config/app.config, and if you see and <client> and <endpoint />, this is where you supply endpoint address. If you need to send client certificate you might want to start with either or and setting security eg:
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
There are lot of resources on WCF capabilities to achieve this. Hope this helps mate.

Message security verification failed.Cannot read KeyIdentifierClause from element 'KeyIdentifier'

Here is the complete error message:
Message security verification failed.
Cannot read KeyIdentifierClause from element 'KeyIdentifier' with namespace
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'.
Custom KeyIdentifierClauses require custom SecurityTokenSerializers, please refer to the SDK for examples
Here is the story: We are trying to implement a WCF client which talks to a non-WCF web service and most likely the web service has been implemented on J2EE platform. The message sent out from WCF client has to be signed. Fortunately, we were able to find a post at stackoverflow and were able to follow the guidelines / tips in that post. Below is the custom binding:
<customBinding>
<binding name="AccountServiceSoap11Binding1" sendTimeout="00:05:00">
<textMessageEncoding messageVersion="Soap11" />
<security authenticationMode="MutualCertificate" enableUnsecuredResponse="true" messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
</security>
<httpsTransport />
</binding>
</customBinding>
We were able to send the request and server responds nicely (we could see the response using fiddler2). Everything works except for the above exception occurred. We did search and found out couple suggestions or clues listed below:
One: sceanairo#12: Incorrect version of security header
blogs.msdn.com/b/distributedservices/archive/2011/03/07/wcf-security-interop-scenarios.aspx
Two: ask vendor to make some changes
social.msdn.microsoft.com/Forums/vstudio/en-US/0732bb4d-7dbb-4b43-8821-3f0caba600eb/cannot-read-keyidentifierclause-from-element-x509issuerserial-with-namespace?forum=wcf
Please advise what we could do to avoid the exception.
Many thanks,
Peter

How do I add TLS to a WCF service?

I've been trying to add TLS to a WCF service, I've created.
Everything is OK until I try to access the service through https instead of http.
When adding the wcf service to the wcf test client, I get this:
Error: Cannot obtain Metadata from [THELINK] If this is a Windows (R)
Communication Foundation service to which you have access, please
check that you have enabled metadata publishing at the specified
address. For help enabling metadata publishing, please refer to the
MSDN documentation at [an MS link] Exchange Error URI: [THELINK]
Metadata contains a reference that cannot be resolved: '[THELINK]'.
There was no endpoint listening at [THELINK] that could accept the
message. This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details. The remote server
returned an error: (403) Forbidden.HTTP GET Error URI: [THELINK]
There was an error downloading '[THELINK]'. The request failed with
HTTP status 403: Forbidden.
Sorry about the link replacing, but I'm new and I don't have the reputation, it seems :)
Regards,
Morten
do you have a
<behaviors>
<serviceBehaviors>
<behavior name="YourSerivceBehaviourName">
<serviceMetadata httpsGetEnabled="true" /> <-- this bit ?
...
...
being referenced by your
<service name="...." behaviorConfiguration="YourSerivceBehaviourName">
or a
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
in your web.config?
the Test client will also moan if the certificate isn't a real one I have found.. ie a self certed one for testing.
but the 403 seems to suggest that whatever credentials you are supplying are incorrect, what is the clientCredentialType set to in the SSL binding?
and what happens if you hit the link in a browser with customerrors off..
this might give you some more useful information

WCF upload large images as wsHttpBinding

I've created a WCF Service to upload images. It works fine with images < 50KB or so but I get "The remote server returned an error: (400) Bad Request." with larger images.
I've been looking for ages and tried lots of different things, including setting the maxRequestLength and several other settings.
On the client-side of things the web.config is picking it up as a basicHttpBinding and I'm after a wsHttpBinding (for the more up-to-date feature-set). If I manually change the the binding type to wsHttpBinding and change the corresponding options, I get a Unsupported Media Type error.
Lookingin the WCF Test Client it shows the service as a basicHttpBinding too.
So my question is two-fold really.
What do I need to do to allow my service to handle files > 50KB?
What do I need to change for my service to be recognised as wsHttp instead of basicHttp?
Apologies if there is a question answering these - I have scoured stackoverflow and tried a few suggestions but it is possible I've missed it!
EDIT: As is always the way, I've managed to solve the wsHttpBinding issue now by fiddling around with the service web.config and manually changing the endpoint to wsHttpBinding. Still getting the large upload filesize issue though.
you will need to update your bindings in you web.config
e.g. this is how i did in my wcf restful service. i believe it will be very similar in your case as well
<bindings>
<webHttpBinding>
<!-- buffer: 64KB; max size: 64MB -->
<binding name="StreamedBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed"
maxBufferPoolSize="67108864" maxBufferSize="65536" maxReceivedMessageSize="67108864">
</binding>
</webHttpBinding>
</bindings>
<service name="WCFRestFul.ApiRestful">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="StreamedBinding" bindingName="StreamedBinding"
contract="WCFRestFul.IApiRestful" behaviorConfiguration="web" />
</service>

WCF, IIS, and Endpoints

Learning WCF (I know, late to the party)
I am working through Juval Lowy's Programming WCF book. I see that I can configure multiple endpoints (including URI's) for my service.
However, when I host these in IIS, only the location of the .svc file seems to matter. Is the multiple endpoints/addresses thing only applicable if you are self-hosting? Am I missing something about hosting services in IIS?
"only the location of the .svc ", you're heading to this because baseaddress are provided by IIS in case of web-hosting (IIS hosting) unless you're using CustomServiceHostFactory. Then whatever value you provide in address, are appended to baseaddress (.svc/..)
You needs to give several host name in IIS for the the same WCF and set several endpoints in the client section of web.config as:
<client>
<endpoint address="hostname1/myservice.svc" ... />
<endpoint address="hostname2/myservice.svc" ... />
<endpoint address="hostname3/myservice.svc" ... />
</client>
Then you can consume them as:
hostname1/myservice.svc
hostname2/myservice.svc
hostname3/myservice.svc

Categories

Resources