c# - Web (ASP.Net) Wcf:未找到从桌面客户端连接时出错
问题描述
我正在使用托管在共享主机帐户上的 WCF 设置 ASP.Net WebForms 子域。WCF 是该网站目前的主要目的。我无法从我的桌面建立链接,从而产生永久
无法连接到远程服务器
我正在尝试Add Service Reference
从 C# 和 C# 中尝试。我希望 C# 代码在客户端的末尾。
我一直在玩弄端口号和不同类型的绑定,但没有任何效果。
网络配置:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6.2"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<system.serviceModel>
<services>
<service name="MyCloud.Communication.CloudService" behaviorConfiguration="BehaviorMyCloudService">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="EndpointBindingMyCloudService"
contract="MyCloud.Communication.ICloudService"
behaviorConfiguration="web"
>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/MyCloudService/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BehaviorMyCloudService">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="8080" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding
name="EndpointBindingMyCloudService"
allowCookies="false"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
maxBufferPoolSize="524288"
maxReceivedMessageSize="2147483647"
messageEncoding="Text"
textEncoding="utf-8"
transactionFlow="false"
useDefaultWebProxy="true"
>
<security mode="None">
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://localhost:8080"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
</configuration>
CloudService.svc(C# 代码):
using System;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.Web;
namespace MyCloud.Communication
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class CloudService : ICloudService, IErrorHandler
{
public UInt16 GetServiceId()
{
return MyCloudLibrary.Constants.My_Id_CloudService;
}
}
}
iCloudService.cs:
using System;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Web;
namespace MyCloud.Communication
{
[ServiceContract(SessionMode = SessionMode.Allowed/*, CallbackContract = typeof(ICallbackCloudService)*/)]
public interface ICloudService
{
[OperationContract(IsOneWay = false)]
[FaultContractAttribute(typeof(CloudServiceFault))]
UInt16 GetServiceId();
}
}
客户端 C# 代码:
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.None;
EndpointAddress endpointAddress = new EndpointAddress("http://Mycloud.asdfmydomain.com/MyCloudService");
var pipeFactory = new ChannelFactory<ICloudService>(binding, endpointAddress);
Program.HostIpcCloudService = pipeFactory.CreateChannel();
Program.HostIpcCloudService.Connect();
CommCloudService.IsPipeCloudService = true;
UInt16 serviceId = Program.HostIpcCloudService.GetServiceId();
客户端 C# 错误:
外部异常:
“在 http://mycloud.asdfmydomain.com/MyCloudService上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。”
内部异常:
“远程服务器返回错误:(404)未找到。”
Add Service Reference
来自的人Visual Studio 2017
说了同样的话。
我从我的 Windows 服务中得到了类似的代码,所以问题可能是我要跨机器,可能是端口,可能是主机帐户上的防火墙等。
一些(但不是全部)参考资料:
想法?
基于答案 1 的更新:
(所以我应该为不得不忍受这个非常烦人的愚人节主题庆祝活动而付出痛苦和痛苦的代价。我正试图专注于编程并保持专注。)
我正在取得进展,还没有骰子。
我的 no service found 错误消息和重复MyCloud.Communication.MyCloud
而不是MyCLoud.Communication.CloudService
错误消息是 Visual Studio 部分重构不完整的结果。Visual Studio 没有重构 .SVC 标记文件。
<%@ ServiceHost Language="C#" Debug="true" Service="MyCloud.Communication.CloudService" CodeBehind="CloudService.svc.cs" %>
在浏览器中指定以下 URL 会产生:
http://mycloud.asdfmydomain.com/Communication/CloudService.svc/Address1
这是来自 Microsoft链接的 URL 的关键部分:
或者,您可以为服务的 ServiceHost 提供基地址,然后为与该服务关联的每个端点指定一个地址,该地址是相对于该基地址定义的。路径:/mathservice.svc/secureEndpoint
我不得不删除注释掉,<serviceHostingEnvironment
因为浏览器想要multipleSiteBindingsEnabled="true"
.
文本说 URI 的第一部分是标签中指定的path to the SVC file
后跟。endpoint address name
EndPointAddres
通过 Chrome 出错:
[ServiceActivationException: The service '/Communication/CloudService.svc' cannot be activated due to an exception during compilation. The exception message is: The endpoint at 'http://mycloud.asdfmydomain.com/Communication/CloudService.svc/Address1' does not have a Binding with the None MessageVersion. 'System.ServiceModel.Description.WebHttpBehavior' is only intended for use with WebHttpBinding or similar bindings..]
通过 C# 出错:
{"The requested service, 'http://mycloud.asdfmydomain.com/Communication/CloudService.svc/Address1' could not be activated. See the server's diagnostic trace logs for more information."}
我正在取得进展。
解决方案
在你的 web.config 你写
<baseAddresses>
<add baseAddress="http://localhost/MyCloudService/"/>
</baseAddresses>
当你调用服务时,地址是http://Mycloud.asdfmydomain.com/MyCloudService,这与你的 web.config 中的地址配置不匹配。
如果你不确定你的服务是什么地址,你可以通过wsdl查看。
例如,我的 web.config 是
<service name="Service.CalculatorService" >
<endpoint address="Calculator.svc/abc/" binding="basicHttpBinding" contract="ServiceInterface.ICalculatorService" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:62193/"/>
</baseAddresses>
</host>
</service>
然后,当我输入我的服务的 wsdl 地址http://localhost:62193/Calculator.svc?singleWsdl的地址时。
你可以看到,即使我只写了一个 Calculator.svc,还有两个 Calculator.svc。
因为 baseaddress 将首先与您的 svc 结合,然后与相对地址结合。所以最终地址将是baseaddree + svc + relativeaddress。
推荐阅读
- java - 如何避免 if else 语句并将它们重写为更小更清晰的代码?
- python - image_url = sys.argv[1] IndexError: 列表索引超出范围
- python - 为什么 python glob.glob 与我传入的通配符不匹配任何文件?
- powershell - 一组数据需要重新排列并导出为 CSV
- javascript - 如何通过 D3 重复和延迟对 API 的调用
- random - 在 Lua 中设置随机种子
- excel - 在 Excel 中使用索引和匹配;为什么命名范围不起作用?
- exception - DAG 从 Web 界面执行 OK,但在通过命令行运行时“失败”
- python - 计算行条目以调整不同的列,Pandas
- javascript - 阻止滚轮事件,直到 scrollIntoView() 完成滚动