Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create WCF client programmatically

I have a website with a Silverlight-enabled WCF service. The service works fine, and I can browse to the WSDL page in the browser with no problems.

Now, I am trying to create a client in a DLL. I need to create the whole client programmatically though, because it is being called in a DLL, which for whatever reason (by design?) won't read the ServiceModel section from its own config file.

So here is my code:

Dim endp As EndpointAddress = New EndpointAddress("http://www.mydomain.com/licensing/lic.svc")
Dim bind As WSHttpBinding = New WSHttpBinding()
Dim svc = New lnt.licClient(bind, endp)
Dim rsp = svc.CheckIt(key)

But when i call the svc.CheckIt method, i get the following error:

Content Type application/soap+xml; charset=utf-8 was not supported by service http://www.mydomain.com/licensing/lic.svc. 
The client and service bindings may be mismatched.
{"The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'application/soap+msbin1'.."}

How do I properly create my client so that these are properly "matched"??
Thanks in advance!!!

like image 205
eidylon Avatar asked Oct 30 '09 16:10

eidylon


2 Answers

Ah --- found it. The ServiceModel section in the website's web.config was set to customBinding. Changed it so it matched what the client was sending, and now it works beautifully.

like image 161
eidylon Avatar answered Oct 01 '22 01:10

eidylon


I ran into this same issue. More spefically my fix was to update the type of bindings I was using. I was using wsHttpBindings instead of basicHttpBindings. This was causing failures as wsHttpBindings uses SOAP 1.2 while basicHttpBindings use SOAP 1.1 and the service I was using required SOAP 1.1

like image 41
dkpatt Avatar answered Oct 01 '22 03:10

dkpatt