“找不到默认终结点元素,该元素引用合同'TFBIC.RCT.HIP.Components.RCTBizTalk.WcfService_TFBIC_RCT_BizTalk_Orchestrations',可能是因为没有找到应用程序的配置文件,或者在客户端元素中没有找到与此合同匹配的终结点元素。”
<endpoint
address="http://nxwtest08bt1/TFBIC.RCT.BizTalk.Orchestrations/WcfService_TFBIC_RCT_BizTalk_Orchestrations.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ITwoWayAsync"
contract="TFBIC.RCT.HIP.Components.RCTBizTalk.WcfService_TFBIC_RCT_BizTalk_Orchestrations"
name="WSHttpBinding_ITwoWayAsync">
<identity>
<userPrincipalName value="NXWTest08BT1\BTAdmin" />
</identity>
</endpoint>
我第一次尝试使用ChannelFactory来指定通常隐藏在配置文件中的参数:
WSHttpBinding myBinding = new WSHttpBinding();
string webServiceURL = "http://localhost/TFBIC.RCT.BizTalk.Orchestrations/WcfService_TFBIC_RCT_BizTalk_Orchestrations.svc";
EndpointAddress myEndpoint = new EndpointAddress(webServiceURL);
ChannelFactory<WcfService_TFBIC_RCT_BizTalk_Orchestrations> myChannelFactory =
new ChannelFactory<WcfService_TFBIC_RCT_BizTalk_Orchestrations>
(myBinding, myEndpoint);
// Create a channel and call the web-service via the channel
WcfService_TFBIC_RCT_BizTalk_Orchestrations wcfClient2 =
myChannelFactory.CreateChannel();
req.PolicyAction = polAction;
resp = wcfClient2.WCFSubmitPolicyAction(req);
propResult = resp.PropertyValuation;
我正在使用Intellisense和myEndPoint变量,但是找不到像"contract"或者"bindingConfiguration"这样的东西。
我的做法是将我的.exe文件复制到一个新目录,并且完全删除<system.serviceModel>
元素/组。我想尝试在没有配置文件的情况下运行。请参考我的相关问题:NUnit tests that call .DLLs that call WCF Web Services (.NET C#)。我试图跟随Gilham的答案,即使我并没有完全理解它。我认为学习ChannelFactory如何工作是第一步。
谢谢,
Neal Walters
附加配置文件部分:
<wsHttpBinding>
<binding
name="WSHttpBinding_ITwoWayAsync" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />;
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />;
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
2019年11月11日下午5点后进行编辑
根据@Marc_s的建议,我认为我终于弄清楚了,在定义通道工厂时将合同放入
<channel>
中。之前,我一直在寻找类似于endpoint.contract="xxx"的东西,因为在配置文件中,合同似乎是endpoint的子参数。
//Not-Fully Qualified Contract
//ChannelFactory<WcfService_TFBIC_RCT_BizTalk_Orchestrations> myChannelFactory =
// new ChannelFactory<WcfService_TFBIC_RCT_BizTalk_Orchestrations>(myBinding, myEndpoint);
//Fully Qualified Contract
ChannelFactory<TFBIC.RCT.HIP.Components.RCTWebService.WcfService_TFBIC_RCT_BizTalk_Orchestrations> myChannelFactory =
new ChannelFactory<TFBIC.RCT.HIP.Components.RCTWebService.WcfService_TFBIC_RCT_BizTalk_Orchestrations>(myBinding, myEndpoint);
为了使上述内容编译通过,我还必须引用我的TBFIC.RCT.HIP.Components(我的.DLL类库调用WCF服务)。当我有配置文件时,尝试了上面的代码,它可以正常运行,但是当我删除配置文件时,仍然会出现以下错误:
“无法找到默认终结点元素,该元素引用合同“TFBIC.RCT.HIP.Components.RCTWebService.WcfService_TFBIC_RCT_BizTalk_Orchestrations”,该合同可能是因为未找到应用程序的配置文件,或者是因为在客户端元素中找不到与此合同匹配的终结点元素。”
现在,我仍然迷惑不解如何消除配置文件的依赖性。我现在使用的确切合同是通道工厂定义中缺失的合同。再次感谢!