c# - cosume webservice应用程序上没有端点
问题描述
我正在学习创建 WCF 服务。我测试了我使用 SoapUi 测试它时有效的服务。现在我正在创建一个测试网站来将此服务添加为服务参考。当我调用服务的方法时,我收到错误“找不到引用合同的默认端点元素”。我搜索了网络,但仍然不知道修复它。有人会帮助我应该做什么或向我展示示例代码。谢谢。
有我的服务配置:
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<authentication mode="Windows"/>
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="Order.IOrders">
<endpoint address="" binding="webHttpBinding" contract="Order.IOrders" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<client>
<endpoint
name=""
address="http://localhost:59837/Order.svc"
binding="basicHttpBinding"
contract="Order.IOrders" />
</client>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
客户端应用程序中的代码:
ServiceReference1.OrdersClient client = new ServiceReference1.OrdersClient();
client.checkOrderNumber(txtNum.Text.ToString());
}
解决方案
根据您的描述和代码详细信息,您似乎想通过添加服务引用来调用 WCF 服务,您需要将WebHttpBehavior添加到客户端端点。
你可以参考下面的代码。
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webEndpoint">
<webHttp defaultBodyStyle="Wrapped"
defaultOutgoingResponseFormat="Xml"
helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint name="myclient" address="http://localhost:9001/Service1.svc" binding="webHttpBinding" contract="ServiceReference1.IService1" behaviorConfiguration="webEndpoint"></endpoint>
</client>
</system.serviceModel>
如果有什么我可以帮忙的,请随时告诉我。
推荐阅读
- python - 为什么我尝试遍历列表列表并更新字典值导致字典未更改?
- php - php if else 在使用 include.php 文件时不起作用,但在直接写入文档时工作正常
- queue - (OMNeT++) 为什么 PacketQueue 总是 0?
- r - 面板回归 - 估计器
- python - 如何使用 Sudo 在生产服务器上配置 Django 电子邮件
- laravel - 如何在 Laravel PHP 中创建邀请系统
- java - 如何从 Java 的 Service 类访问 MethodChannel?
- java - objectOutputStream 的readObject() 方法没有接收到写在inputStream 上的对象给Client?
- c# - C# 模拟设置返回取决于其他方法执行的顺序
- javascript - For循环跳过迭代