我创建了一项服务,该服务从数据库(所有客户,客户按电话号码等)返回客户信息。我已将服务发布到我们的服务器,并创建一个Windows应用程序来调用该服务。在我创建应用程序并开始调用我的服务中的第一个函数(GetCustomersAll)之前,一切都运行顺利。当我运行应用程序时没有任何反应。我必须在结尾处设置一个断点,这样我才能让它返回错误。我最终收到的错误是“收到HTTP响应到http:// ........时发生错误。这可能是由于服务端点绑定不使用HTTP协议。这也可能是由于HTTP请求上下文被服务器中止(可能是由于服务关闭)。“
我刚刚离开学校和第一份工作。在这种情况下,我的主管无法帮助我,所以我希望这里有人可以为我提供一些见解,并指出我在摆脱这个错误方面的正确方向。我的网络配置如下:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="DemoProjectsConnectionString" connectionString="Data Source=PORTALDEV;Initial Catalog=DemoProjects;Persist Security Info=True;User ID=DemoProjectUser;Password=demo"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
<!--<httpRuntime targetFramework="3.5"/>-->
<httpRuntime maxRequestLength="102400" executionTimeout="3600" />
</system.web>
<system.serviceModel>
<client>
<endpoint address="http://portaldev.ethosdomain1.ethosgroup.com:9000/Service1.svc" binding="basicHttpBinding" bindingConfiguration="GetCustomersHTTPBinding" contract="Demo2.IService1"></endpoint>
</client>
<bindings>
<basicHttpBinding>
<binding name="GetCustomersHTTPBinding" receiveTimeout="01:30:00">
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Demo2.Service1">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="GetCustomersHTTPBinding" contract="Demo2.IService1"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<!-- 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>
</behaviors>
</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>
</configuration>
的App.config
<?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="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://portaldev.ethosdomain1.ethosgroup.com:9000/Service1.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="Demo2ServiceReference.IService1" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
Form1.vb的:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btnAllCustomers_Click(sender As Object, e As EventArgs) Handles btnAllCustomers.Click
Dim MyService As Demo2ServiceReference.Service1Client = New Demo2ServiceReference.Service1Client
Dim listofcustomers As New List(Of Demo2ServiceReference.Customer)
Try
MyService.Open()
listofcustomers = MyService.GetCustomersAll()
For Each customer As Demo2ServiceReference.Customer In listofcustomers
lblAllCustomers.Text += "Customer Id: " & customer.CustomerId & ", Customer Name: " & customer.FirstName & " " & customer.LastName &
"<br/>"
Next
MyService.Close()
Catch ex As Exception
MsgBox(ex.Message)
MyService.Abort()
End Try
End Sub
End Class
我已经尝试过使用运行时版本,端点地址以及其他人在这个主题上发布的一些解决方案,但我已经走到了尽头。如果有人能提供一些见解,我将不胜感激。谢谢!
*如果我理解正确,该服务将托管在IIS中。至于端点,应该只有一个吗?