Calling Services via .NET SvcUtil generated proxies

  • 1
  • Question
  • Updated 5 months ago
  • Answered
I have the following code to call the UserList/GetData service:

var binding = new System.ServiceModel.BasicHttpsBinding();
binding.Security.Mode = System.ServiceModel.BasicHttpsSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic;
            
var endpoint = new System.ServiceModel.EndpointAddress(helpers.endpointUrl + "services/UserListService1.svc/GetData");
var userService = new UserListService1.ListService1Client(binding, endpoint);
            
userService.ClientCredentials.UserName.UserName = helpers.userName;
userService.ClientCredentials.UserName.Password = helpers.loginPassword;

var users = userService.GetData(1, 10, new[]
{
   new Uri("urn:replicon:user-list-column:user"),
   new Uri("urn:replicon:user-list-column:user-name"),
   new Uri("urn:replicon:user-list-column:login-name"),
   new Uri("urn:replicon:user-list-column:email-address"),
   new Uri("urn:replicon:user-list-column:department"),
}, null, null);

This is returning the following error:

System.ServiceModel.ProtocolException: 'The content type application/json; charset=utf-8 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 174 bytes of the response were: 
'{"error":{"code":"InternalServiceFault","correlationId":"8d37d4eab01447f5843f8a43a613fad1","reason":"The server was unable to process the request due to an internal error."}}'.'

Is there a standard way to properly set the encoding?
Photo of Drury-Green, Grant

Drury-Green, Grant

  • 10 Posts
  • 0 Reply Likes

Posted 5 months ago

  • 1
Photo of Akbar Ali Khan

Akbar Ali Khan, Official Rep

  • 185 Posts
  • 5 Reply Likes
Hi Grant,

Could you provide me with the content type that is being used in the code?

We recommend that you use the content type as application/json if you are using text/xml as the content type.

Thanks,
Akbar
(Edited)
Photo of Drury-Green, Grant

Drury-Green, Grant

  • 10 Posts
  • 0 Reply Likes
That's what I'm asking... how do I set the content type to application/json within the C# code?

To explain further - I'm using SvcUtil (via adding a 'service reference' within Visual Studio) to generate proxies directly against your WSDL... I don't understand why the generated proxies are not aware of the correct encoding type - I've never had to specify them when adding a service reference before
(Edited)
Photo of Akbar Ali Khan

Akbar Ali Khan, Official Rep

  • 185 Posts
  • 5 Reply Likes
Hi Grant,

Please refer to the sample code to get all enabled users present on the link mentioned below.

Link : https://www.replicon.com/help/getallenabledusers-c-example/
Photo of Drury-Green, Grant

Drury-Green, Grant

  • 10 Posts
  • 0 Reply Likes
I'm sorry - that is not an answer to my question. The referenced code is not using generated proxies.

The proxy generation will generate .NET classes for the request and response types - rather than relying on magic strings and JObjects...
(Edited)
Photo of Akbar Ali Khan

Akbar Ali Khan, Official Rep

  • 185 Posts
  • 5 Reply Likes
Hi Grant,

i will have our support team reach out to you about this.

Thanks,
Akbar.