我是WCF技术的新手。我有以下情况:VS的一个实例包含WCF类库和客户端主机,Silverlight应用程序的第二个实例。我运行一个客户端主机,然后运行Silverlight应用程序,我得到错误: “无法在ServiceModel客户端配置部分找到名称为'WSHttpBinding_IEvalService'且合同'EmailWCFServiceReference.IEvalService'的端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为找不到与此名称匹配的端点元素客户元素。“
我的代码:
<behaviors>
<serviceBehaviors>
<behavior name="MetaData">
<serviceMetadata httpGetEnabled="true"
httpGetUrl="http://localhost:8080/evals/meta" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MetaData" name="EvalServiceLibrary.EvalService">
<endpoint address="http://127.0.0.1:8080/evals/basic"
binding="basicHttpBinding"
contract="EvalServiceLibrary.IEvalService" />
<endpoint address="http://127.0.0.1:8080/evals/ws"
binding="wsHttpBinding"
contract="EvalServiceLibrary.IEvalService" />
<endpoint address="net.tcp://127.0.0.1:8081/evals"
binding="netTcpBinding"
contract="EvalServiceLibrary.IEvalService"/>
<endpoint address="http://localhost:8080/evals/mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<endpoint address="net.tcp://localhost:8081/evals/mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
</service>
</services>
在Silverlight中:
EvalServiceClient channel = new EvalServiceClient("WSHttpBinding_IEvalService");
Eval eval = new Eval();
channel.GetEvalsCompleted += (t, r) =>
{
if (!r.Cancelled && r.Error == null)
grOdebrane.ItemsSource = r.Result;
else
MessageBox.Show("Nie ma danych");
};
channel.GetEvalsAsync();
好的我将WSHttpBinding_IEvalService更改为BasicBinding_IEvalService并且我有另一个错误:“尝试向URI发出请求时出错'http://127.0.0.1:8080/evals/basic'。这可能是由于尝试在没有适当的跨域策略的情况下以跨域方式访问服务,或者不适合SOAP服务的策略。您可能需要联系服务的所有者以发布跨域策略文件并确保它允许发送与SOAP相关的HTTP头。这个错误也可能是由于在不使用InternalsVisibleToAttribute属性的情况下在Web服务代理中使用内部类型引起的。请参阅内部异常以获取更多详细信息。“