将逗号分隔的字符串值传递给 wcf 休息服务 [英] passing comma separated string value to a wcf rest service

查看:42
本文介绍了将逗号分隔的字符串值传递给 wcf 休息服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

wcf 休息服务有以下问题

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 是逗号分隔的字符串参数

ABC US,ABC UK are comma separated string arguments

问题是,当我在本地尝试此操作时,它工作得很好,但是当我在远程主机上尝试此操作时,浏览器只显示无法显示页面.不知道iis上有没有什么设置.

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.

我在 iis 上托管服务.

I am hosting the service on iis.

这是来自远程 iis 的响应

this is the response from the remote iis

失败

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

写入日志的错误是对象图中可以序列化或反序列化的最大项目数为65536".更改对象图或增加 MaxItemsInObjectGraph 配额.

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(因为逗号分隔的值被去掉了,只传递了一个参数)

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/

以下是我的代码

  [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>

任何帮助将不胜感激

推荐答案

这是我在配置行为中所做的更改以对其进行排序,

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>

基本上从 endpointBehaviors 转移到 serviceBehaviors

basically moved from endpointBehaviors to serviceBehaviors

这篇关于将逗号分隔的字符串值传递给 wcf 休息服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆