我正在嘗試編寫一個程序,該程序將消息發送到一個服務並接受另一個服務中的響應。發送服務已由另一位開發人員編寫,因此我的任務是向該sendMessage服務發送請求並將響應記錄在我的服務(AcceptMessage)服務中。無法進入我本地託管的WCF類庫
我寫了一個WCF類庫,並試圖將其託管在Windows窗體項目中。
這裏是結構我
項目1個名爲-WCF類庫 - AcceptMessage
項目2 - 具有服務參考SendMessageservice並參考Windows窗體我接受服務類庫。這個項目也託管我的接受消息服務。
私人無效Form1_Load的(對象發件人,EventArgs的) {
ServiceHost host = new ServiceHost(typeof(Operator)); BindingElementCollection bec = new BindingElementCollection(); SymmetricSecurityBindingElement ssbe = new SymmetricSecurityBindingElement(); ssbe.LocalServiceSettings.InactivityTimeout = new TimeSpan(0, 10, 0); bec.Add(ssbe); bec.Add(new TextMessageEncodingBindingElement()); bec.Add(new HttpsTransportBindingElement()); CustomBinding customBinding = new CustomBinding(bec); host.AddServiceEndpoint(typeof(AcceptService.Operator), customBinding, BaseAddress); }
這部分是我發送請求,並檢查是否正確地發送
private void btnSendMessage_Click_1(object sender, EventArgs e) { var client = new SendMessageService.OperatorClient(); //SendUNIMessage params - Transaction Type and Message Byte result = client.SendUNIMessage("Add", txtRequest.Text); txtResponse.Text = result == 0 ? "Request sent - Success" : "Request sent - Failed"; }
Web.config中的消息
<appSettings> <!--<add key="AcceptMessageServiceAddress" value="http:/localhost/AcceptService"/>--> <add key="AcceptMessageServiceAddress" value="http://localhost/AcceptService"/> </appSettings> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="UNI.Endpoint.Basic" /> </basicHttpBinding> </bindings> <client> <endpoint address="http://insomeotherserver/sendmessage.asmx" binding="basicHttpBinding" bindingConfiguration="UNI.Endpoint.Basic" contract="SendMessageService.IOperator" name="UNI.Endpoint.Basic" /> </client> <behaviors> <serviceBehaviors> <behavior name="TestAcceptService.IOperator"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="TestAcceptService.AcceptServiceBehavior" name="TestAcceptService.AcceptService"> <endpoint address="" binding="wsHttpBinding" contract="TestAcceptService.IOperator"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost/AcceptService" /> </baseAddresses> </host> </service>
我現在的問題是我可以將消息發送到發送服務,但是我的中斷點並未打到名爲Operator的Acceptmessage服務類。這就是我將所有迴應記錄到本地驅動器的地方。
我試圖從我的表單客戶端項目附加服務,但沒有幫助。
謝謝您的幫助。