繁体   English   中英

WCF 服务无应答。 PHP 结果错误获取 http 标头,

[英]WCF service no answer. PHP result Error Fetching http headers,

我有 WCF 服务

[ServiceContract(Name = "Test")]
public interface ITest {
    [OperationContract]
        string test1();
}
[DataContract]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = false)]
public class csTest : ITest {
    public string test1() {
        Thread.Sleep(60000);
        return "test1";
    }
}

开始他们

ServiceHost TestHost= new ServiceHost(typeof(HostHCS.Test.csTest), new Uri("http://127.0.0.1:8150/Test"));
            ServiceConfigureHttp(TestHost, crtSMBHttp("127.0.0.1","Test","8150"), crtSDB(), typeof(HostHCS.Test.ITest), crtBndHttp(), ip, "Test");
            TestHost.Open();
private void ServiceConfigureHttp(ServiceHost service, ServiceMetadataBehavior serviceMetadataBehavior, ServiceDebugBehavior serviceDebugBehavior, Type serviceType, BasicHttpBinding bind, string ip, string servName) {
        service.Description.Behaviors.Remove(typeof(ServiceMetadataBehavior));
        service.Description.Behaviors.Add(serviceMetadataBehavior);
        service.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
        service.Description.Behaviors.Add(serviceDebugBehavior);
        service.AddServiceEndpoint(serviceType, new WSHttpBinding(),"");

        service.AddServiceEndpoint(
System.ServiceModel.Description.ServiceMetadataBehavior.MexContractName, 
System.ServiceModel.Description.
MetadataExchangeBindings.CreateMexHttpBinding(), 
 "http://127.0.0.1:8150/Test/mex");
    }
    private BasicHttpBinding crtBndHttp() {
        BasicHttpBinding binding = new BasicHttpBinding();
        binding.MaxReceivedMessageSize = Int32.MaxValue;
        XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
        readerQuotas.MaxArrayLength = Int32.MaxValue;
        readerQuotas.MaxStringContentLength = Int32.MaxValue;
        readerQuotas.MaxBytesPerRead = Int32.MaxValue;
        readerQuotas.MaxDepth = Int32.MaxValue;

        binding.ReaderQuotas = readerQuotas;
        binding.MaxBufferPoolSize = Int32.MaxValue;

        binding.OpenTimeout = new TimeSpan(1, 00, 0);
        binding.CloseTimeout = new TimeSpan(1, 00, 0);
        binding.SendTimeout = new TimeSpan(1, 00, 0);
        binding.ReceiveTimeout = new TimeSpan(1, 00, 0);
        return binding;
    }

    private ServiceMetadataBehavior crtSMBHttp(string ip, string servName,string port) {

        ServiceMetadataBehavior myServiceMetadataBehavior = new ServiceMetadataBehavior();
        myServiceMetadataBehavior.HttpGetEnabled = true;
        myServiceMetadataBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
        return myServiceMetadataBehavior;
    }

我的 php 代码

<?php
try{ 
ini_set('default_socket_timeout', 600); //120/// 6000//60000
$client = new SoapClient(
'http://127.0.0.1:8150/Test?wsdl',
array(
    'soap_version' => SOAP_1_2, 
    'cache_wsdl' => WSDL_CACHE_NONE, 
    'trace' => 1,
    'exception' => 1,
    'keep_alive' => 0,
    'connection_timeout' => 60000//500000
));
$webService = $client->test1();
} catch (Exception $e) {

print  'Caught exception: '.  $e->getTraceAsString(). "<br/>";
print  'Caught exception: '.  $e->getMessage(). "<br/>";
var_dump($client->__getLastRequestHeaders());
print    "<br/>";
var_dump($client->__getLastRequest());
print    "<br/>";
var_dump($client->__getLastResponse());
print    "<br/>";
}
?>

很快返回结果

捕获的异常:#0 [内部函数]:SoapClient->__doRequest('__call('test1', Array) #2 {main}

捕获的异常:获取 http 标头时出错

string(204) "POST /Test HTTP/1.1 Host: 127.0.0.1:8150 Connection: close User-Agent: PHP-SOAP/7.3.2 Content-Type: application/soap+xml; charset=utf-8; action= “http://tempuri.org/Test/test1”内容长度:186“

字符串(186)“”

NULL

也就是说,没有调用 service 方法,因为只在一分钟后才收到结果。 可能是什么问题,我做错了什么?

错误如下。 PHP 不适用于 WSHttpBinding,如果被替换

service.AddServiceEndpoint(serviceType, new WSHttpBinding(),"");

service.AddServiceEndpoint(serviceType, new BasicHttpBinding(),"");

并在 php 客户端更改版本 soap 客户端

'soap_version' => SOAP_1_2,

'soap_version' => SOAP_1_1,

那么一切都会奏效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM