WCF服务有一个方法(比如说TestMethod),我尝试创建一个像这样的文件流:
System.IO.FileStream fs = new System.IO.FileStream(@"D:\Test.xml", System.IO.FileMode.Open);
Run Code Online (Sandbox Code Playgroud)
我的客户端和服务是相同的解决方案.
当客户端调用TestMethod(在Web服务中公开)时,它将给出以下错误:
对"D:\ DXDirectoryAuth.xml"路径的访问被拒绝.
请帮忙!!
我正在使用WCF在C#中编写客户端/服务器应用程序.我的所有测试都没问题,但是一旦我部署了服务,我发现与服务器通信时出现了随机问题.我启用了调试并在服务器中看到了这样的消息:
The communication object, System.ServiceModel.Channels.ServerReliableDuplexSessionChannel, cannot be used for communication because it has been Aborted.
Run Code Online (Sandbox Code Playgroud)
模式是这样的:
应用程序如下所示:服务实例提供了与数据库交互的API方法,其类型为"netTcpBinding".几个客户端(大约40个)连接并从服务中随机调用方法.即使没有发送或接收任何东西,客户也可以保持开放几天.
以下是相关位:
服务:
[ServiceContract(CallbackContract = typeof(ISVCCallback), SessionMode = SessionMode.Required)]
[ExceptionMarshallingBehavior]
...
Run Code Online (Sandbox Code Playgroud)
和
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext=true)]
public class SVCService : ISVC
...
Run Code Online (Sandbox Code Playgroud)
服务配置:
<behaviors>
<serviceBehaviors>
<behavior name="behaviorConfig">
<serviceMetadata httpGetEnabled="false" httpGetUrl="" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="1000"
maxConcurrentInstances="50" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="tcpBinding" closeTimeout="00:01:00" openTimeout="00:10:00"
receiveTimeout="23:59:59" sendTimeout="00:01:30" transferMode="Buffered"
listenBacklog="1000" …Run Code Online (Sandbox Code Playgroud) 添加服务引用时,它会使用默认构造函数创建"MyServiceClient"类.如果我使用新的MyServiceClient(),我会收到一个错误:无法找到默认端点...如果我使用新的MyServiceClient("endpointName"),它就可以工作.
我想在app/web.config中指定一个默认端点,当我使用默认构造函数时,它将被使用.我知道我可以将该默认名称放在*.settings中并在我的应用程序中使用它,但只是想知道是否有任何内置方法来执行它.
我创建了WCF,我使用wsHttpBinding和MTOM作为消息传输,认证为"Windows".
现在我的服务不是当前的SECURE,它是普通的HTTP,在自定义端口上运行.
WCF的wsHttpBinding的Windows身份验证是否安全?任何人都可以看到密码或通过网络跟踪猜测?
环境信息:
这是app.config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metaAndErrors">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceAuthorization impersonateCallerForAllOperations="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="CustomServiceHost.CustomService"
behaviorConfiguration="metaAndErrors"
>
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="wsHttpLargeBinding"
contract="CustomServiceHost.ICustomService"/>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:89/CustomService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding
name="wsHttpLargeBinding" messageEncoding="Mtom"
maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="512000"/>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
以下是在运行时完成的客户端配置,
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Message.ClientCredentialType
= MessageCredentialType.Windows;
binding.Security.Mode = SecurityMode.Message;
binding.MessageEncoding = …Run Code Online (Sandbox Code Playgroud) 如何在调用WCF服务时定义WCF客户端使用的LocalEndPoint(如果客户端计算机有多个IP地址)?
我有一台位于DMZ中的机器有两个IP地址,外部IP地址可以通过防火墙通过我们位于外部服务提供商的网络服务器的VPN连接到达.在此计算机上运行基于WCF和Unity的自定义应用程序服务器,该服务器应充当代理或应用程序级网关(ALG).它应接受来自Web服务器的服务调用,并使用wcf客户端工厂重新生成服务调用,将它们转发到LAN中的真实应用服务器.
当使用wcf客户端工厂在此代理上重新创建服务调用时,wcf客户端应使用此计算机的第二个内部IP地址,因为只允许来自此内部IP地址的消息通过防火墙才能到达局域网中的应用服务器.不幸的是,我们的wcf客户端代理始终选择使用第一个"外部"IP地址创建传出消息.我正在寻找一种方法来明确设置wcf客户端代理使用的IP地址.
我只能找到一个允许定义LocalEndPoint或ClientBaseAddress的WCF绑定元素:CompositeDuplexBindingElement.据我所知,这个属性是告诉服务器在哪里发送asynch回复消息,所以它与我正在寻找的设置不同.
任何想法我能做些什么才能找到可行的解决方案?
提前感谢任何有用的建议!!
这似乎是一个类似的问题,只使用TcpClient/Sockets而不是WCF: 在C#中指定用于TCPClient/Socket的传出IP地址
另一个,这次是关于SoapClient: 在发送传出请求之前将新的SoapClient绑定到特定的IP地址
我正在扩展WebHttpBehavior以公开具有自定义序列化和反序列化的WCF REST服务(以及与该问题无关的一定数量的其他功能).
新行为使用实现IDispatchMessageFormatter来执行服务所服务的POCO的自定义序列化和反序列化,并通过SerializeReply和DeserializeRequest方法发送给它.
我可以完全按照我需要的方式提供XML和JSON SerializeReply.
我可以毫无问题地反序列化XML,但是我似乎无法找到反序列化JSON消息的方法,因为我无法获取Message参数中包含的纯文本DeserializeRequest.
这就是现在的代码DeserializeRequest:
if (format == System.ServiceModel.Web.WebMessageFormat.Json)
{
var data = ""; // TODO obtain plain text from Message object
var json = JsonConvert.DeserializeObject(data, paramType, new IsoDateTimeConverter(), new StringEnumConverter());
parameters[paramIndex] = json;
}
else
{
var serializer = new System.Xml.Serialization.XmlSerializer(paramType, string.Empty);
var reader = message.GetReaderAtBodyContents();
parameters[paramIndex] = serializer.Deserialize(reader);
}
Run Code Online (Sandbox Code Playgroud)
关于如何从Message对象获取纯文本以便反序列化的任何建议将不胜感激.
如果您认为我的方法有问题,我也希望在评论中听到它.
我在StackOverflow和其他地方看到了几个关于这个错误的线程但是,我一直无法得到解决我的问题的方法.
我有一个尝试调用Web服务方法的应用程序.当它调用一个方法(提供登录验证)时,它工作得很好.然后,当它调用另一个函数(不是登录/成员资格相关)时,它会生成此错误:
由于EndpointDispatcher上的ContractFilter不匹配,因此无法在接收方处理带有Action'http://tempuri.org/IMyAppData/GetSomeSpecialXML ' 的消息.这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配.检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无).
我重建并重新发布了Web服务,然后从客户端应用程序中删除了服务引用并重新创建它们.我仍然得到错误.以下是客户端应用程序的app.config文件中的相关XML:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyAppData" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://legolas.vectorcsp.home/MyAppSyncService/MyAppData.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyAppData"
contract="MyAppData.IMyAppData" name="BasicHttpBinding_IMyAppData" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
这是Web服务的web.config文件中的相关XML:
<behaviors>
<serviceBehaviors>
<behavior name="MyAppDataSvc.MyAppDataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
Run Code Online (Sandbox Code Playgroud)
这一切都发生在我的本地机器上.我只是想在客户端应用程序上进行开发.任何人都可以建议我可能尝试发现问题所在.
提前感谢您提出的任何建议.
更新:我做了更多测试.我已将Web服务发布到开发服务器,而不是本地计算机.我仍然得到同样的错误.我已经浏览了应用程序和Web服务的配置文件,我找不到任何问题.我已将新创建的Web服务的web.config文件与先前版本的Web服务的web.config文件进行了比较,但我没有看到任何问题.我将桌面应用程序的app.config文件的相关部分与Web服务的现有客户端的web.config文件进行了比较,但我找不到任何差异.
我已使用Microsoft Service …
我正在寻找使用.net 4 wcf服务进行动态路由的示例.请帮我.
我正在开发一个使用WCF服务的SharePoint工作流 - 事实是,我无法正确部署app.config文件.这就是我所说的:
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:55693/Service1.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
name="WSHttpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我无法找到如何动态地设置代码,有人会这么善良并指出我正确的方向吗?
Default.aspx.cs
WCFService.Service1Client client = new WCFService.Service1Client();
string stream = client.JsonSerializeFromDatabase();
client.Close();
WCFService.Service1Client client2 = new WCFService.Service1Client();
foreach (WCFService.Person in client2.JsonDeserializeFromDatabase(stream))
Run Code Online (Sandbox Code Playgroud)
Service1.svc.cs
public IList<Person> JsonDeserializeFromDatabase(string value)
{
MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(value));
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<Person>));
IList<Person> tableData = (IList<Person>)ser.ReadObject(ms);
ms.Close();
ms.Dispose();
return tableData;
}
Run Code Online (Sandbox Code Playgroud)
IService1.cs
[OperationContract]
IList<Person> JsonDeserializeFromDatabase(string value);
Run Code Online (Sandbox Code Playgroud)
服务器Web.config
<httpRuntime maxRequestLength="8192"/>
</system.web>
...
<system.serviceModel>
<services>
<service name="TestWCF.Service1" behaviorConfiguration="TestWCF.Service1Behavior">
<endpoint address="" binding="wsHttpBinding" contract="TestWCF.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="TestWCF.Service1Behavior">
<serviceMetadata …Run Code Online (Sandbox Code Playgroud) wcf httpresponse wcf-binding wcf-data-services json-deserialization
wcf-binding ×10
wcf ×8
wcf-client ×3
.net ×1
c# ×1
endpoint ×1
httpresponse ×1
ip-address ×1
json ×1
sharepoint ×1
wcf-routing ×1
wcf-security ×1
windows ×1