我们有一个R服务器 (R是一种用于统计分析的编程语言),它基本上采用脚本和csv文件,处理一些数据并将结果作为文本返回.
我需要在R服务器上编写一个服务,以便.net客户端(可能是.Net Windows Forms或ASP.Net)可以连接到R服务器,提交脚本和CSV文件,然后返回结果.
我对可用的许多不同的绑定感到困惑,网络上的信息似乎很稀疏/分散于选择的内容.
另外,最好是在IIS中运行服务,还是作为单独的"命令行"类型监听器服务(后者看起来比IIS更难看,我不知道为什么有人会选择这样做,如果他们可以在IIS中运行它)?
我有一个WCF服务的以下服务器端app.config:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="default" maxReceivedMessageSize="5000000">
<readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Core.TOAService.Service1Behavior"
name="Core.TOAService.TOAService">
<endpoint address="" binding="wsHttpBinding" contract="Core.TOAService.ITOAService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/Core.TOAService/TOAService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Core.TOAService.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set …Run Code Online (Sandbox Code Playgroud) 我对元数据发布概念感到困惑.
如果在WCF服务配置文件中我写了:
<serviceMetadata httpGetEnabled="false"/>
Run Code Online (Sandbox Code Playgroud)
无论是真是假.当我尝试使用"添加服务引用..."在客户端应用程序中提供服务引用并单击"发现"时,我能够检索服务引用.
但删除以下两行: -
<endpoint address="mex" binding="mexBasicHttpBinding" contract="IMetadataExchange"/>
<serviceMetadata httpGetEnabled="false"/>
Run Code Online (Sandbox Code Playgroud)
如今后,当我试图给使用客户端应用程序引用"添加服务引用...",并点击"查看",我不能够检索服务参考.
现在任何人都可以告诉我它究竟意味着什么.为什么在将其设置为False之后仍然允许设置参考.为什么在删除这些行之后它不允许设置引用.
-Anil
构建应用程序时,它通常部署在不同的环境(test,dev,prod)中,因此端点地址正在发生变化.由于ServiceReferences.ClientConfig是作为Silverlight的.xap文件的一部分构建的,因此在构建解决方案后很难更改端点,这通常是通过web.config完成的.
我已经搜索了很多,但是我无法弄清楚这里的最佳做法是什么,所以我的问题是:
在Silverlight中进行动态wcf端点地址配置时,最佳做法是什么?
为了澄清,根据应用程序所在的服务器(test,dev,prod),端点会发生变化:
<endpoint
name="MyService"
address="http://testserv/MyService.svc"
binding="basicHttpBinding"
bindingConfiguration="MybasicHttpBinding"
contract="MyApp.MyService"
/>
<endpoint
name="MyService"
address="http://prodserv/MyService.svc"
binding="basicHttpBinding"
bindingConfiguration="MybasicHttpBinding"
contract="MyApp.MyService"
/>
Run Code Online (Sandbox Code Playgroud)
在某种程度上,我需要Silverlight客户端知道使用哪一个,具体取决于它在哪个服务器上/哪个构建编译.
我们在使用有速度问题Azure的服务总线中继既netTcpRelayBinding和basicHttpRelayBinding.对于小消息大小(10K),中继以低延迟(100ms)运行,但随着消息大小增加(100K),我们经历看似随机的响应时间(600ms-1000ms).我们希望改善较大邮件的延迟成本.
是否正在使用通过服务总线中继支持的消息压缩(gzip,protobuf-net等)?有没有人通过中继启用请求/响应压缩成功?通过IIS支持响应压缩是微不足道的,但我们希望支持请求压缩以提高延迟成本.由于我们无法用Fiddler来描述中继,我们如何知道消息在通过中继时仍然被压缩?
我们发现一个有趣的观点是,在后续消息中继(2s)之间引入延迟,我们可以获得更好的性能(100K - 200ms).可能是更大的消息被自动限制?知道触发限制条件的消息大小截止值会很高兴.
对于我们的测试 - 我们只是向服务中继发送一个随机消息字符串,并从服务器回送请求字符串.我们尝试了来自多个地理位置的此客户端/服务器(以排除防火墙/ Web过滤器问题)并遇到相同的延迟行为.
public class ServiceRelayProfiler : IServiceRelayProfiler
{
public string HelloProfiler(string name)
{
return string.Format("Hello {0}", name);
}
}
Run Code Online (Sandbox Code Playgroud)
ChannelFactory<IServiceRelayProfiler> channelFactory = new ChannelFactory<IServiceRelayProfiler>("helloProfilerTcp");
IServiceRelayProfiler channel = channelFactory.CreateChannel();
string message = RandomString(100000); // 100K
for (int i = …Run Code Online (Sandbox Code Playgroud) 我想通过URL访问服务中公开的所有方法.如果假设URL将是:
http://localhost/MyService/MyService.svc
Run Code Online (Sandbox Code Playgroud)
我如何访问方法:
我希望能够通过WCF在我正在设计的托管框架内托管和连接到vanilla套接字服务器.我希望能够使用WCF来编码今天必须由套接字程序员手动管理的传输和协议通信.这将允许我与Linux服务器守护程序的最终互操作性,除了传统的套接字和专有协议之外什么也不暴露.我只对此时通常使用WcfTestClient验证传输通道层感兴趣.我的理解是WcfTestClient不支持复杂的服务方法.
有人认为可以使WcfTestClient适用于自定义传输通道吗? 能够通常使用此客户端来测试任意数量的自定义传输通道将是非常好的.
我正在努力了解Windows SDK中包含的WCF Udp示例,该示例通常位于C:\ Program Files\Microsoft SDKs\Windows\v6.1\Samples\WCFSamples\TechnologySamples\Extensibility\Transport\Udp\CS,假设WCFSamples.zip文件是从Samples目录中完全解压缩的.
这是我到目前为止采取的步骤:
(成功):在Visual Studio 2008中成功运行解决方案的服务和客户端.
(成功):使用通常位于C:\ Program Files\Microsoft Visual Studio 9.0\Common7\IDE的WcfTestClient连接到MEX端点
(失败):使用WcfTestClient尝试从ICalculatorContract或IDatagramContract服务合同执行方法.
例如,当我执行Hello()方法时,我收到以下错误:
友情致辞:
无法调用该服务.可能的原因:服务离线或无法访问; 客户端配置与代理不匹配; 现有代理无效.有关更多详细信息,请参阅堆栈跟踪.您可以尝试通过启动新代理,还原到默认配置或刷新服务来进行恢复.
错误详情:
具有合同"IDatagramContract"的ServiceEndpoint上的CustomBinding缺少TransportBindingElement.每个绑定必须至少有一个派生自TransportBindingElement的绑定元素.在System.ServiceModel.Channels.Binding.EnsureInvariants(字符串contractName)在System.ServiceModel.Description.ServiceEndpoint.EnsureInvariants()在System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint)在System.ServiceModel.ChannelFactory.CreateFactory()在System.ServiceModel.ChannelFactory.OnOpening()处于System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)的System.ServiceModel.ChannelFactory.EnsureOpened()处于System.ServiceModel.ChannelFactory
1.CreateChannel(EndpointAddress address, Uri via) at System.ServiceModel.ChannelFactory1.CreateChannel()在System.ServiceModel.ClientBase1.CreateChannel() at System.ServiceModel.ClientBase1.CreateChannelInternal()在System.ServiceModel.ClientBase`1.get_Channel()在DatagramContractClient.Hello()
在UdpTransport项目中定义的UdpTransportBindingElement肯定是从TransportBindingElement派生的,如下所示,所以我认为WcfTestClient配置文件中必定缺少某些内容和/或可能我必须以某种方式为测试客户端提供更多信息.我尝试将Udp解决方案的客户端项目的System.ServiceModel部分复制到WcfTestClient的配置文件中,以及将传输程序集dll复制到与测试客户端相同的文件夹中,但是我收到了同样的错误.
我的理解是MEX端点应该足以获得调用服务上的简单方法所需的信息.当然,我理解这个故事可能还有更多,考虑到我正在努力创建一个旨在测试开箱即用传输通道的客户端与自定义传输通道一起工作.
/// <summary>
/// Udp Binding Element.
/// Used to configure and construct Udp ChannelFactories and ChannelListeners.
/// </summary>
public class UdpTransportBindingElement
: TransportBindingElement // to signal that we're a transport
, IPolicyExportExtension // for policy …Run Code Online (Sandbox Code Playgroud) WCF消息交换模式中Request-Response和Duplex之间的主要区别是什么?
我尝试使用独立应用程序使用WCF Web服务.我能够使用Internet Explorer查看此服务,也可以在Visual Studio服务引用中查看.
这是我得到的错误
The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8).
Run Code Online (Sandbox Code Playgroud)
如何更改此选项以使用正确的内容类型?
这是我的配置文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="G2WebServiceSoap11Binding" />
</basicHttpBinding>
<customBinding>
<binding name="G2WebServiceSoap12Binding">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap11Endpoint/"
binding="basicHttpBinding" bindingConfiguration="G2WebServiceSoap11Binding"
contract="G2ServiceReference.G2WebServicePortType"
name="G2WebServiceHttpSoap11Endpoint" />
<endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap12Endpoint/"
binding="customBinding" bindingConfiguration="G2WebServiceSoap12Binding"
contract="G2ServiceReference.G2WebServicePortType"
name="G2WebServiceHttpSoap12Endpoint" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
这是堆栈
{System.ServiceModel.ProtocolException: The content type application/xml;charset=utf-8 of …Run Code Online (Sandbox Code Playgroud) wcf-binding ×10
wcf ×8
c# ×4
.net ×3
azure ×1
binding ×1
interface ×1
metadata ×1
performance ×1
silverlight ×1
wcf-client ×1