PHP到WCF与SoapClient - 请求实体太大

时间:2015-06-04 09:05:02

标签: c# php web-services soap soap-client

我有一个soap svc web服务,这些是我的WS方法:

StoreService.svc.cs

namespace StoreServices
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class StoreService : IStoreService
    {
        public bool SaveCarData(Car car)
        {
            //Some code
        }
    }
}

IStoreService.cs

namespace StoreServices
{
    [ServiceContract]
    public interface IStoreService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/SaveCarData", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        bool SaveCarData(Car car);
    }
}

在我的WS web.config中,我已经调出所有缓冲区来发送和接收大数据:

的web.config

  <system.web>
    <httpRuntime targetFramework="4.0" maxRequestLength ="2147483647" executionTimeout="999999"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" receiveTimeout="10:00:00" closeTimeout="10:00:00"
          sendTimeout="10:00:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647" openTimeout="10:00:00" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://myDomain.pt/WStore/StoreService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
        contract="StoreServices.IStoreService"
        name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>

我的客户这样称呼我的服务:

<?php

ini_set('default_socket_timeout', 360000);

class Car
{
  public $Id=0;
  public $Name="My new car";
  public $Description="";
  public $ImageBase64="";
}


$car_toInsert = new Car();
$requestParams = array('car' => $car_toInsert);

try {
    $time_start = microtime(true);

    $client = new SoapClient('http://myDomain.pt/WStore/StoreService.svc?wsdl', 
        array('encoding'=>'ISO-8859-1', 'keep_alive' => true,
            'trace' => 1,
            'exceptions'=> 1,
            'connection_timeout'=> 3600));

    $response = $client->SaveCarData($requestParams);   
    print_r($response);

} catch (Exception $e) {
    $time_request = (microtime(true)-$time_start);
    if(ini_get('default_socket_timeout') < $time_request) {
        //Timeout error!
        print_r("request time bigger");
    } else {
        //other error
        //$error = $e->getMessage();
        print_r($e->getMessage());
    }
} 
?>

我的客户已经开启了他的“缓冲区”,如here中所述。

现在的问题是:当我的客户端发送一个“短”Car.ImageBase64字符串时,这很好用,但当Car.ImageBase64字符串很大时,他可以与我的WS通信并得到这个错误:< strong> 请求实体太大

短ImageBase64示例:

class Car
{
  public $Id=0;
  public $Name="My new car";
  public $Description="";
  public $ImageBase64="data:image/jpg;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7";
}

巨大的ImageBase64示例:

我的ImageBase64字符串示例太大,无法在此问题表单中插入。请在http://d3eaqdewfg2crq.cloudfront.net/wp-content/uploads/carousel/main-reporting/report.png中插入网址“here”并编码为base64。

问题是什么?我们如何解决这个问题?我已经模拟了我的客户端通信来测试一些东西,我发现他正在发出一个http GET请求。我认为这可能是问题,我想将其更改为http POST。我怎么能在PHP代码中执行此操作?

Error php request headers

我还尝试更改我的网络配置,例如this,但我收到了“ SOAP-ERROR:解析WSDL:找不到...... ”错误。

1 个答案:

答案 0 :(得分:0)

解决!经过多次搜索和修改后,我终于通过新的web.config更改解决了这个问题。我如何没有客户端端点,而是与我的WS通信的所有客户端的服务器端点。我还需要创建一个新服务(同一个WCF项目中的svc和接口文件)并将我的web.confi更改为:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IStoreService" 
                 receiveTimeout="10:00:00" 
                 closeTimeout="10:00:00" 
                 sendTimeout="10:00:00" 
                 maxBufferPoolSize="2147483647" 
                 maxBufferSize="2147483647"
                 maxReceivedMessageSize="2147483647" 
                 openTimeout="10:00:00"/>
        <binding name="BasicHttpBinding_IServiceIntegration" 
                 receiveTimeout="10:00:00" 
                 closeTimeout="10:00:00" 
                 sendTimeout="10:00:00" 
                 maxBufferPoolSize="2147483647" 
                 maxBufferSize="2147483647"
                 maxReceivedMessageSize="2147483647" 
                 openTimeout="10:00:00">
                  <readerQuotas
                      maxDepth="2147483647"
                      maxStringContentLength="2147483647"
                      maxArrayLength="2147483647"
                      maxBytesPerRead="2147483647"
                      maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
     <service name="StoreServices.StoreService" behaviorConfiguration="StoreServicesBehavior"/>

      <service name="StoreServices.IntegrationService" behaviorConfiguration="IntegrationServicesBehavior">
        <endpoint address="" 
                  binding="basicHttpBinding" 
                  contract="StoreServices.IIntegrationService"
                  bindingConfiguration="BasicHttpBinding_IServiceIntegration" />
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
      </service>

    </services>
    <behaviors>
       <serviceBehaviors>
        <behavior name="StoreServicesBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>

        <behavior name="IntegrationServicesBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add factory="System.ServiceModel.Activation.WebServiceHostFactory" 
            relativeAddress="./StoreServices/StoreService.svc" 
            service="StoreServices.StoreService" />
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.serviceModel>