【发布时间】:2026-02-03 16:30:01
【问题描述】:
我有两个由托管服务提供商托管的 WCF 服务。两种服务都可以正常工作。我可以从我自己的计算机甚至是由其他提供商托管的网站访问它们。奇怪的部分(至少,我不明白的部分)是;一个人不能打电话给另一个人。
这两个服务都位于 Web 根目录的子文件夹中,处于相同的层级。像 wwwroot\serviceone 和 wwwroot\servicetwo。两者都被标记为 IIS 中的应用程序文件夹,两者都有一个几乎相似的 web.config,如下所示,只是名称不同:
<configuration>
<system.web>
<compilation targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="servone">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="MyService.ServiceOne" behaviorConfiguration="servone">
<endpoint address="" binding="basicHttpBinding" contract=" MyService.IServiceOne "/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
浏览 .svc 会显示带有示例代码的知名服务页面;
class Test
{
static void Main()
{
ServiceOne client = new ServiceOne ();
// Use the 'client' variable to call operations on the service.
// Always close the client.
client.Close();
}
}
客户端有一个名为 HandleRequest(string str) 的方法。所以在我的代码(C#)中有这样一行;
client.HandleRequest("blah");
调用不会引发异常(我可以说是因为它们被捕获、处理并写入数据库)。这就像消息已发送但永远不会返回。 当我在本地运行此服务(谁调用另一个)并将第二个留在远程服务器上时,一切正常。
显然,很难提供主办方的所有详细信息。不幸的是,我也无法访问 IIS 安装来模拟环境。因此,基于我能提供的少量信息,我并不期待深入的技术解决方案。但任何关于此设置与其他设置有何不同的评论都可能会有所帮助。
非常感谢您的努力,谢谢。
编辑:
调用如下:
public bool Send(String str)
{
bool result = false;
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress ep = new EndpointAddress("http://www.mydomain.com/ServiceTwo.svc");
client = new ServiceTwoClient(b, ep);
//
try
{
result = client.HandleRequest(str);
client.Close();
return result;
}
catch (Exception x)
{
Add2DbLog(x.Message);
return false;
}
}
【问题讨论】:
-
你能展示一下服务#1调用服务#2的代码吗?
-
开启message logging 可能会帮助您调试此问题。
-
@Keith - 感谢您的建议。我正在看它。唯一的问题是我不允许使用绝对路径。我更新了帖子以解决您的问题。
-
我强烈建议将
client.Close()移动到finally块中,以确保即使服务失败也关闭对象。否则,连接将保持打开状态,一段时间后,新连接将在打开时超时。 -
是否有可能
client.HandleRequest(str)抛出异常但Add2DbLog未能记录它?