passing comma separated string value to a wcf rest

2019-08-30 01:48发布

问题:

Having the following issue with wcf rest service

I am trying to access this endpoint from a browser,

https://localhost:443/Service1.svc/json/GetCustomerData/ABC US,ABC UK/MQA/

ABC US,ABC UK are comma separated string arguments

the trouble is when I tried this on my local it works perfectly fine but when I try this on the remote host then the browser just shows page cannot be displayed. I am not sure if there is some setting to be made on iis.

I am hosting the service on iis.

this is the response from the remote iis

fails

https://remoteserver:443/Service1.svc/json/GetCustomerData/ABC US,ABC UK/MQA/

the error that gets written to the log is Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota.

I think this is misleading as well. Also I am using a self signed certificate

passes(because the comma separated value is removed and just a single argument is passed)

https://remoteserver:443/Service1.svc/json/GetCustomerData/ABC UK/MQA/

following is my code

  [OperationContract]
    [WebInvoke(Method = "GET", UriTemplate = "GetCustomerData/{postcode}/{dept}", ResponseFormat = WebMessageFormat.Json)]
    IEnumerable<Customer> GetCustomerData(string postcode, string dept);

//interface implementation
IEnumerable<Customer> GetCustomerData(string postcode, string dept);
{
    return new Customer
               {
                   Name = "Customer 1",
                   Add1 = "Address Line 1"
                   ...etc
               };
}

following is the config I am using

<system.serviceModel>
    <services>
      <service name="Service1" behaviorConfiguration="httpsBehavior">
            <endpoint address="json" binding="webHttpBinding" contract="ICustomerData" behaviorConfiguration="web"
                      bindingConfiguration="webHttpBindingTransportSecurity"/>
            <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
          </service>
    </services>

    <bindings>
      <webHttpBinding>
        <binding name="webHttpBindingTransportSecurity" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior name="httpsBehavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>

      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

Any help will be much appreciated

回答1:

This is the change I made in the config behaviors to sort it,

<behaviors>
  <serviceBehaviors>
    <behavior name="httpsBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>

  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

basically moved from endpointBehaviors to serviceBehaviors



标签: wcf rest