【发布时间】:2021-01-03 15:41:43
【问题描述】:
我对 WCF 还很陌生,所以我在 web.config 上苦苦挣扎。
我在 IIS10 上创建了 WCF 服务。这是我的 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<system.web>
<customErrors mode="Off" />
<compilation targetFramework="4.0" debug="true">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="DefaultCache" duration="60" varyByParam="none" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
<authentication mode="Windows" />
</system.web>
<system.serviceModel>
<services>
<service name="FileStorageService.FileService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration" contract="FileStorageService.IFileService" />
<!--<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />-->
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfiguration">
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<httpErrors errorMode="Detailed" />
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings>
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
我可以引用该 api,但是当我尝试使用它时收到此消息:
服务器堆栈跟踪:在 System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(消息 回复、MessageFault 故障、字符串操作、MessageVersion 版本、 故障转换器故障转换器)在 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime 操作,ProxyRpc& rpc) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串动作, Boolean oneway, ProxyOperationRuntime 操作, Object[] ins, Object[] 出局,TimeSpan 超时)在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime 操作)在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 留言)
在 [0] 处重新抛出异常:在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(消息数据& msgData,Int32 类型)在 PpsTransactionFile.MyFileServiceReference.IFileService.DownloadPpsZipFile(DownloadFileRequest 下载文件请求)在 PpsTransactionFile.MyFileServiceReference.FileServiceClient.DownloadPpsZipFile(DownloadFileRequest downloadFileRequest) 在 D:\Source\Sub\Web 项目\WebStorageApps\PpsTransactionFile\Service References\MyFileServiceReference\Reference.cs:第 493 行 PpsTransactionFile.download.DownloadFile.DownloadPpsZipFile(FileParms fileParms) 在 D:\Source\Sub\Web 项目\WebStorageApps\PpsTransactionFile\download\DownloadFile.cs:line 155
我的代码:
public static Status DownloadPpsTransactionFile(FileParms fileParms)
{
var client = new FileServiceClient();
try
{
var downloadstatus = new Status();
downloadstatus.ProgramSendType = fileParms.SendGet;
client.ClientCredentials.UserName.UserName = "xxxxxx";
client.ClientCredentials.UserName.Password = "xxxxxxxxxxx";
var trucks = fileParms.Trucks.Split(Convert.ToChar(","));
foreach (var truck in trucks)
{
int trk;
if (!int.TryParse(truck, out trk))
{
continue;
}
var downloadrequest = new DownloadFileRequest();
downloadrequest.CompanyCode = fileParms.CompanyCode;
downloadrequest.FileType = 1;
downloadrequest.TruckNumber = trk;
DownloadFileResponse download;
do
{
download = client.DownloadPpsTransactionFile(downloadrequest);
当我调用 wfc 方法时,它在最后一行失败。我似乎无法让 IIS 设置和 web.config 正常工作。
我在 IIS 上的设置:
我做错了什么?
客户端配置
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFileService">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://SOMEDOMAIN.COM/api/fileservice/FileService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFileService"
contract="MyFileServiceReference.IFileService" name="BasicHttpBinding_IFileService" />
</client>
</system.serviceModel>
</configuration>
附加信息
我在事件查看器中找到了这个。我目前正在研究它以了解它的含义。
FailedRequestTracing 模块未能将缓冲事件写入日志 匹配失败定义的请求的文件。不会有日志 生成,直到这种情况得到纠正。问题发生在 在最后 5 分钟内至少 1 次。数据就是错误。
【问题讨论】:
-
异常信息是什么?另外,服务器是否暴露在 ssl 上?
-
什么是客户端 WCF 配置?如果您有一个 C# 客户端 - 那是一个带有
app.config的命令行应用程序 - 那是什么样的?它是一个带有web.config的网络应用程序 - 那么它是什么样的?您必须在客户端具有“相同”配置才能与您在服务器上定义的 WCF 服务通信。 -
@WiktorZychla 谢谢回复。如果您要问的话,我已经安装了 ssl 证书?
-
@marc_s 我已经发布了客户端配置。
-
@marc_s 这是一个连接到 IIS10 托管的 WCF 服务的 winforms 应用程序。我在上面发布了网络和应用配置,这是否回答了您的问题?