我试图弄清楚为什么客户端应用程序启动后第一次WCF调用与第二次调用相比需要更多时间.
我做了什么测试:
basicHttpBinding为了减少网络和安全开销.在我的测试中,我看到第一次呼叫约700毫秒,第二次呼叫约3毫秒.
几乎一秒似乎是JIT编译器的太多时间.我会接受,如果那个时间用于初始化一些复杂的基础设施,如ObjectContext实体框架,但我的代码非常简单,代理类已经编译.
我也试过netNamedPipeBinding绑定.结果证明模式 - 第一次调用需要~800 ms,第二次调用需要~8 ms.
如果有人能解释为什么第一次服务电话会花费这么多时间,我们将不胜感激.
在Win 7 64位中测试过.
我的实现如下.
合同:
[ServiceContract]
public interface ICounter
{
[OperationContract]
int Add(int num);
}
Run Code Online (Sandbox Code Playgroud)
服务实施:
public class CounterService: ICounter
{
private int _value = 0;
public int Add(int num)
{
_value += num;
Console.WriteLine("Method Add called with argument {0}. Method returned {1}", num, _value);
return _value;
}
}
Run Code Online (Sandbox Code Playgroud)
服务器实施:
class Program
{
static void Main(string[] …Run Code Online (Sandbox Code Playgroud) 我在我们的一台服务器上的Windows服务中托管WCF服务.在使用basicHttpBinding并在.NET中构建测试客户端(最终工作)后,我继续尝试使用SoapClient类从PHP访问它.最终的消费者将是一个PHP站点,所以我需要在PHP中使用它.
当我必须在PHP代码中的SoapClient类的构造函数中输入WSDL url时,我感到难过.WSDL在哪里?我只有:
http://172.27.7.123:8000/WordService和 http://172.27.7.123:8000/WordService/mex
这些都不会暴露WSDL.
作为WCF的新手,我可能会问一个愚蠢的事情(或者我可能在某处有错误的假设).请温柔:D
不,http://172.27.7.123:8000/WordService?wsdl没有显示任何不同于http://172.27.7.123:8000/WordService :(
我被迫在IIS中托管它吗?我是否被迫使用常规WebService?
.NET 3.5,VS2008,使用BasicHttpBinding的WCF服务
我有一个Windows服务托管的WCF服务.当Windows服务因升级,定期维护等原因关闭时,我需要正常关闭我的WCF服务.WCF服务的方法可能需要几秒钟才能完成,而典型的卷每秒会有2-5个方法调用.我需要以允许任何先前调用方法完成的方式关闭WCF服务,同时拒绝任何新调用.通过这种方式,我可以在约5-10秒内达到安静状态,然后完成Windows服务的关闭周期.
调用ServiceHost.Close似乎是正确的方法,但它会立即关闭客户端连接,而无需等待任何正在进行的方法完成.我的WCF服务完成了它的方法,但没有人发送响应,因为客户端已经断开连接.这是此问题提出的解决方案.
以下是事件序列:
我需要的是让客户端连接保持打开,以便客户知道他们的服务方法成功完成.现在他们只是获得了一个封闭的连接,并且不知道服务方法是否成功完成.在使用WCF之前,我使用套接字并且能够通过直接控制Socket来实现.(即在仍然执行接收和发送时停止接受循环)
关闭主机HTTP端口非常重要,以便上游防火墙可以将流量定向到另一个主机系统,但现有连接保持打开状态以允许现有方法调用完成.
有没有办法在WCF中实现这一目标?
我尝试过的事情:
谢谢
编辑:不幸的是,我无法实现系统正在关闭的应用程序级别的建议响应,因为该领域的客户端已经部署.(我只控制服务,而不是客户端)
编辑:我使用Redgate Reflector来查看Microsoft的ServiceHost.Close实现.不幸的是,它调用了internal我的代码无法访问的一些辅助类.
编辑:我还没有找到我想要的完整解决方案,但Benjamin建议在输入服务方法之前使用IMessageDispatchInspector拒绝请求.
我遇到了问题,因为我有一个带有wsHttpBinding的Web服务:
<endpoint address="" binding="wsHttpBinding" contract="BindingTest.IService1" />
Run Code Online (Sandbox Code Playgroud)
我无法让我的python代码调用它,每次我尝试调用时都会收到此错误消息:
Exception: (400, u'Bad Request')
Run Code Online (Sandbox Code Playgroud)
经过多次调查并在互联网上搜索后,我只是在我的Web服务中指定了basicHttpBinding:
<endpoint address="basic" binding="basicHttpBinding" contract="BindingTest.IService1" />
Run Code Online (Sandbox Code Playgroud)
通过这种方式,我可以从python代码调用Web服务!
现在我的问题是另一个:我无法真正修改Web服务,我可以在本地尝试,但我没有权限修改它.
那么,有没有办法在python中指定一个"wsHttpBinding"请求?
这是我的实际代码:
import logging
from suds.client import Client
import sys
from suds.sax.element import Element
handler = logging.StreamHandler(sys.stderr)
logger = logging.getLogger('suds.transport.http')
logger.setLevel(logging.DEBUG), handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
client =Client('Service_URL')
client.set_options(headers={'Content-Type': 'application/soap+xml; charset=utf-8'})
result = client.service.RouteDocument('Input')
Run Code Online (Sandbox Code Playgroud) 我已经看到这个问题发布了一百万次,但没有一个解决方案对我有用......所以我去了:
调用WCF服务时,我收到以下错误:
格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数 http://BlanketImportService.ServiceContracts/2011/06:request时出错.InnerException消息是'反序列化BlanketImport.BlanketImportRequest类型的对象时出错.读取XML数据时已超出最大数组长度配额(16384).通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象上的MaxArrayLength属性,可以增加此配额.第1行,第44440行.'.有关更多详细信息,请参阅InnerException.
我修改了readerQuotas客户端服务器,并应用了bindingConfiguration标签.
这是服务器配置:
<bindings>
<basicHttpBinding>
<binding name="BilagImportBinding" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="BlanketImport">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BilagImportBinding" bindingNamespace="http://BlanketImportService.ServiceContracts/2011/06" contract="BlanketImport.IBlanketImport">
</endpoint>
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
而客户端配置:
<bindings>
<basicHttpBinding>
<binding name="BilagImportBinding" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/BlanketImport/BlanketService.svc"
binding="basicHttpBinding" bindingConfiguration="BilagImportBinding" contract="BlanketServiceReference.IBlanketService"
name="BasicHttpBinding_IBlanketService" />
</client>
Run Code Online (Sandbox Code Playgroud) 我有一个使用基本访问身份验证的WCF SOAP服务.SSL没有被使用 - 我理解这里的安全问题.
使用WCFTestClient应用程序我已经通过在服务中临时硬编码用户名和密码来验证服务的工作原理,当Authorization标头不存在时使用.
我现在正在尝试编写一个通过Authorization标头传递凭据的测试应用程序.我在我的测试应用程序中添加了对我的服务的服务引用,但Authorizationhttp请求中没有标题.生成的MyServiceClient类使用System.ServiceModel.ClientBase
在我的测试应用程序中,我将如下设置凭据
MyServiceClient client = new MyServiceClient("BasicHttpBinding_MyService");
client.ClientCredentials.UserName.UserName = "WebServiceUsername";
client.ClientCredentials.UserName.Password = "WebServicepassword";
Run Code Online (Sandbox Code Playgroud)
我也尝试过如下
MyServiceClient client = new MyServiceClient();
ClientCredentials loginCredentials = new ClientCredentials();
loginCredentials.UserName.UserName = "WebServiceUsername";
loginCredentials.UserName.Password = "WebServicepassword";
client.Endpoint.Behaviors.Remove(client.Endpoint.Behaviors.Find<ClientCredentials>());
client.Endpoint.Behaviors.Add(loginCredentials);
Run Code Online (Sandbox Code Playgroud)
服务web.config如下
<services>
<service name="MyService" behaviorConfiguration="MyBehavior" >
<endpoint contract="MyService" binding="basicHttpBinding" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
测试app.config如下
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_MyService">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何设置我的web.config(客户端)以使用另一个使用另一个使用另一个不同的WCF Web服务
我有两个端点,我想我需要两个不同的Binding配置.这是我当前的绑定节点:
<basicHttpBinding>
<binding name="WebServiceProxyServiceSoapBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)
我无法添加另一个basicHttpBinding节点.问题是,如果我改变的是模式参数,<security mode="Transport">那么绑定对于一个或另一个端点将起作用.
这似乎是一个常见的问题,但还没有找到答案.总的来说,在简单的消费和调用之外,我对WCF(如果不是很明显)的体验并不是很好.任何帮助都会很棒!
这篇文章很接近但不完全相同,因为它们不需要不同的安全模式: 如何从一个客户端使用多个WCF服务
提前致谢.
我有使用basicHttpBinding的WCF服务.
当客户端和服务器在同一网络上时,它们的初始呼叫会持续大约30秒而不是平稳.
当我使用DNS通过互联网从客户端进行同样的呼叫时,它可以很好地工作,没有挂起.
客户端和服务器都是控制台应用程序 服务器正在运行Windows 7,有问题的客户端正在运行Windows Server 2008.同一网络上的两台计算机都使用其本地安全策略,因此没有域控制器.
关闭所有防火墙和防病毒软件并没有解决我的问题.
这是来自设置的日志,彼此相邻
09:33:05,252 [1] DEBUG ChannelFactoryManager: Created ClientChannel http://192.168.1.11:18762/DiagnosticService
09:33:05,263 [1] INFO Program: WcfAppender.InitializeWcfAppender: 08:33:05
09:33:05,274 [1] INFO Program: File.Copy(C:temptest.txt, O:test.txt, true): 08:33:05
09:33:05,298 [1] INFO Program: GETTING DomainFactory.LoggingDiagnosticService.GetMonitoringLevel: 08:33:05
09:33:32,661 [1] INFO Program: GOT DomainFactory.LoggingDiagnosticService.GetMonitoringLevel: 08:33:32
09:33:32,668 [1] INFO Program: GETTING DomainFactory.LoggingDiagnosticService.GetMonitoringLevel: 08:33:32
09:33:32,680 [1] INFO Program: GOT DomainFactory.LoggingDiagnosticService.GetMonitoringLevel: 08:33:32
09:33:32,693 [1] INFO Program: File.Copy(C:temptest.txt, O:test.txt, true): 08:33:32
Run Code Online (Sandbox Code Playgroud)
当我从不同网络通过互联网点击同一台服务器时,这是日志:没有延迟:
09:36:56,500 [1] DEBUG ChannelFactoryManager: Created ClientChannel http://mydomain.com:18762/DiagnosticService
09:36:56,501 [1] INFO Program: WcfAppender.InitializeWcfAppender: …Run Code Online (Sandbox Code Playgroud) 在WCF中使用BasicHttpBinding和NetHttpBinding有什么区别?我似乎无法找到任何参考..
我正在 .NET Core 中重写一个调用外部 Web 服务的控制台应用程序。
我目前收到以下错误:
发生了一个或多个错误。(HTTP 请求未经授权,客户端身份验证方案为“匿名”。从服务器收到的身份验证标头为“NTLM,协商”。)
我能够通过更新 App.config 在旧版本的应用程序中解决这个问题,如下所示:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="EmployeeSoap" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="Ntlm" />
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
</binding>
<binding name="EmployeeSoap1" />
</basicHttpBinding>
<customBinding>
<binding name="EmployeeSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://..." binding="basicHttpBinding" bindingConfiguration="EmployeeSoap" contract="TEST.EmployeeSoap" name="EmployeeSoap" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我似乎找不到任何好的资源来展示我如何在 .NET Core 中实现这一点。我希望有人能指出我正确的方向。
提前致谢。
basichttpbinding ×10
wcf ×9
c# ×4
.net ×2
.net-4.0 ×1
.net-core ×1
binding ×1
networking ×1
performance ×1
php ×1
python ×1
url ×1
web-services ×1
wsdl ×1