Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以访问WCF服务操作的子集_C#_.net_Service_Wcf - Fatal编程技术网

C# 是否可以访问WCF服务操作的子集

C# 是否可以访问WCF服务操作的子集,c#,.net,service,wcf,C#,.net,Service,Wcf,我有以下疑问: 考虑以下事项: /* My service is formed by several subservices (subfunctionalities). Here is functionality 1 */ [ServiceContract] public interface IMySubService1 { [OperationContract] int MyOp11(string opnd); [OperationContract] int M

我有以下疑问: 考虑以下事项:

/* My service is formed by several subservices 
   (subfunctionalities). Here is functionality 1 */
[ServiceContract]
public interface IMySubService1 {
   [OperationContract]
   int MyOp11(string opnd);
   [OperationContract]
   int MyOp12(stirng opnd);
}

/* My service is formed by several subservices 
   (subfunctionalities). Here is functionality 2 */
[ServiceContract]
public interface IMySubService2 {
   [OperationContract]
   int MyOp21(string opnd);
   [OperationContract]
   int MyOp22(stirng opnd);
}

/* My service is formed by several subservices 
   (subfunctionalities). Here is functionality 3 */
[ServiceContract]
public interface IMySubService3 {
   [OperationContract]
   int MyOp31(string opnd);
   [OperationContract]
   int MyOp32(stirng opnd);
}
/* My server will implement a complex great 
   service made of the previously introduced subservices. */
[ServiceContract]
public interface IMyService : IMySubService1, IMySubService2, IMySubService3 {
}
以及以下各项:

/* My service is formed by several subservices 
   (subfunctionalities). Here is functionality 1 */
[ServiceContract]
public interface IMySubService1 {
   [OperationContract]
   int MyOp11(string opnd);
   [OperationContract]
   int MyOp12(stirng opnd);
}

/* My service is formed by several subservices 
   (subfunctionalities). Here is functionality 2 */
[ServiceContract]
public interface IMySubService2 {
   [OperationContract]
   int MyOp21(string opnd);
   [OperationContract]
   int MyOp22(stirng opnd);
}

/* My service is formed by several subservices 
   (subfunctionalities). Here is functionality 3 */
[ServiceContract]
public interface IMySubService3 {
   [OperationContract]
   int MyOp31(string opnd);
   [OperationContract]
   int MyOp32(stirng opnd);
}
/* My server will implement a complex great 
   service made of the previously introduced subservices. */
[ServiceContract]
public interface IMyService : IMySubService1, IMySubService2, IMySubService3 {
}
那么,我将实施我的服务:

// Implementing the service
public class MyService : IMyService {
   ...
}
好的!到现在为止,没有什么奇怪的! 我的服务将托管在服务器上,我很高兴:) 该服务(例如)托管在svc文件上,但请记住该服务是
IMyService

现在让我们进入正题: 在我的客户机中,我想创建一个客户机,以便只访问我服务的一个子集。考虑到我的服务是三个子服务的融合,我只想访问一个子服务

例如,我的客户对
IMySubService1
我能做以下事情吗

ServiceEndpoint httpEndpoint = new ServiceEndpoint(
   ContractDescription.GetContract(typeof(IMySubService1)), 
   new BasicHttpBinding(), 
   new EndpointAddress("http://tempuri.org/MyService.svc/ServiceCall")
   );
ChannelFactory<IMySubService1> channelFactory = 
   new ChannelFactory<IMySubService1>(httpEndpoint);

IMySubService1svc = channelFactory.CreateChannel();
/* Calling methods in IMySubService1 */
int i1 = svc.MyOp11("A string");
int i2 = svc.MyOp12("Another string");
int i3 = svc.MyOp11("And another string");
int i4 = svc.MyOp12("In the end a string");
int i5 = svc.MyOp11("The final string");
ServiceEndpoint httpEndpoint=新的ServiceEndpoint(
ContractDescription.GetContract(类型为(IMySubService1)),
新的BasicHttpBinding(),
新端点地址(“http://tempuri.org/MyService.svc/ServiceCall")
);
ChannelFactory ChannelFactory=
新ChannelFactory(httpEndpoint);
IMySubService1svc=channelFactory.CreateChannel();
/*在IMySubService1中调用方法*/
inti1=svc.MyOp11(“字符串”);
inti2=svc.MyOp12(“另一个字符串”);
int i3=svc.MyOp11(“和另一个字符串”);
inti4=svc.MyOp12(“最后是一个字符串”);
int i5=svc.MyOp11(“最终字符串”);

这可能吗?

嗯,很有趣。在我看来,它应该像
ServiceContract
属性的
Name
Namespace
属性一样工作在较小的子合同上。这些值应该与服务对组合合约的期望值相匹配。

好! 我终于试过了


这是可以做到的!!!与我在问题中所展示的方式完全相同。

您试过了吗?如果它不起作用,你会犯什么错误?对不起,这只是好奇。。。我没有试过:嗯,试一下,应该不会花太长时间:)是的,重点是现在我在国外,三天后我会回来,,,只是想提前知道这一点,我没有太多时间花在电脑前(没有我的开发工具):(很好的问题!!但这似乎是不可能的