如何创建wcf服务 [英] how to create wcf service

查看:82
本文介绍了如何创建wcf服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有

i拥有一组学院,并通过wcf服务管理中心办公室收到的数据,收到的数据如下:

教师信息:新老师,更新老师和删除老师,...

学生信息:新生,更新学生和删除学生,...

...



1-是否需要在单独的服务中拆分?

2-如何以及如何将服务主机应用程序的App.config文件中的服务地址合并到客户端使用我的服务在单个添加服务参考?



即这是我的服务合同:

hi all
i have group of academies and manages received data in central office by a wcf service ,received data is as followed:
Teacher info :new teacher ,update teacher and delete teacher ,...
student info :new student ,update student and delete student ,...
...

1- does it need to split in separate service?
2- how and can i combine service address in App.config file of service host app to client use my services in single add service reference?

i.e this is my service contract:

[ServiceContract]
public interface ITeacher
    {
        [OperationContract]
        void Add(Teacher teacher);
        [OperationContract]
        void Update(Teacher teacher);

        [OperationContract]
        void Delete(Teacher teacher);
    } 
[ServiceContract]
public interface IStudent
        {
            [OperationContract]
            void Add(Student student);
            [OperationContract]
            void Update(Student student)
            [OperationContract]
            void Delete(Student Student);
        }







<system.serviceModel>
    <services>
      <service name="BusManagmentService.StudentService">

        <endpoint address="" binding="basicHttpBinding" contract="BusManagmentService.IStudent">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/BusManagmentService/IStudent/" />
          </baseAddresses>
        </host>
      </service>
      <service name="BusManagmentService.TeacherService">
        <endpoint address="" binding="basicHttpBinding" contract="BusManagmentService.ITeacher">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/BusManagmentService/ITeacher/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information,
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <!-- 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="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

推荐答案

1.您不需要拆分它们。你应该只有一个类,所有方法都应该返回一个错误代码(对于数据库错误),你应该重命名这样的方法:

1.You do not need to split them. You should have only one class, all method should return an error code (for database errors) and you should rename the method like this:
int AddTeacher(Teacher teacher);



2.如果您按照我上面的建议行事,您的第二个问题将自动解决。



3.还有定义和使用多服务合同的可能性,但在您的情况下没有说明。有关详细信息,请参阅下一篇文章: http:// www。 c-sharpcorner.com/uploadfile/dhananjaycoder/multiple-service-contracts-in-wcf-service/ [ ^ ]


这篇关于如何创建wcf服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆