none
adding service referece for SharePoint in the Class Library RRS feed

  • Question

  • Hi there,

    I create a Class Library and a WCF for the SharePoint. currently I add Service reference in the class library to use it for testing. but I got an error when I new an Instance.

    I refer to "https://blogs.msdn.microsoft.com/dsnotes/2015/04/09/wcf-consuming-wcf-web-service-in-a-dll/". do u know how to deal with it.? is there any solution on it.?


    Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.



    • Edited by Will .H Monday, October 21, 2019 4:17 PM
    Monday, October 21, 2019 2:57 PM

Answers

  • Hi,

    My sample test demo.

    Custom wcf as below demo.

    http://dvsivakrishna.blogspot.com/2014/05/creating-custom-wcf-rest-service-for.html

    Update SharePoint WCF configuration file.

    <system.serviceModel>    
    	<behaviors>
          <serviceBehaviors>
            <behavior name="MyServiceServiceBehavior">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true">
              </serviceMetadata>
              <serviceDebug includeExceptionDetailInFaults="true">
              </serviceDebug>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="jsonBehaviour">
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>
    	<bindings>
      <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
        <services>
          <service name="SPCustomWCF.Service1" behaviorConfiguration="MyServiceServiceBehavior">
            <endpoint address="/GetData" binding="basicHttpBinding" contract="SPCustomWCF.IService1">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
            </endpoint>
          </service>
        </services>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
        </serviceHostingEnvironment>
      </system.serviceModel>



    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, October 22, 2019 7:30 AM

All replies

  • hi willh,

    what do you mean by wcf lived in sharepoint? 

    as per my understanding you are trying to consume a wcf service method(op contract) from a console application. If so then you either need to host your wcf service on iis or as a self hosting service.

    to make it work what you can do is - right click run your service project. once your service is running right click on console application reference and click on add a service reference. you will see your service there. once you add the service reference you will get a proxy in your project to call the service method. this link will help you-

    https://docs.microsoft.com/en-us/visualstudio/data-tools/walkthrough-creating-a-simple-wcf-service-in-windows-forms?view=vs-2019


    K Mohit

    Monday, October 21, 2019 3:21 PM
  • Hi K Mohit,

    Thanks

    1. what do you mean by wcf lived in sharepoint?  -> I mean I create a custom WCF Service for SharePoint
    2. I follow the article you provide with me, it show me the error like the above shown. 

    so I have no idea on it.


    Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.

    Monday, October 21, 2019 3:46 PM
  • hi willh,

    where and how you are deploying your wcf. it should not give this error. 

    is there any blogs that you have used as a reference.

    this link https://blogs.msdn.microsoft.com/dsnotes/2015/04/09/wcf-consuming-wcf-web-service-in-a-dll/ is hosting the wcf service to the local iis express server taking advantage of visual studio feature.


    K Mohit

    Monday, October 21, 2019 8:44 PM
  • Hi K Mohit, I deploy it to the SharePoint iSAPI

    Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.

    Tuesday, October 22, 2019 1:10 AM
  • Hi,

    My sample test demo.

    Custom wcf as below demo.

    http://dvsivakrishna.blogspot.com/2014/05/creating-custom-wcf-rest-service-for.html

    Update SharePoint WCF configuration file.

    <system.serviceModel>    
    	<behaviors>
          <serviceBehaviors>
            <behavior name="MyServiceServiceBehavior">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true">
              </serviceMetadata>
              <serviceDebug includeExceptionDetailInFaults="true">
              </serviceDebug>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="jsonBehaviour">
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>
    	<bindings>
      <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
        <services>
          <service name="SPCustomWCF.Service1" behaviorConfiguration="MyServiceServiceBehavior">
            <endpoint address="/GetData" binding="basicHttpBinding" contract="SPCustomWCF.IService1">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
            </endpoint>
          </service>
        </services>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
        </serviceHostingEnvironment>
      </system.serviceModel>



    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, October 22, 2019 7:30 AM
  • Hi Lee,

    thanks for your help. It works properly.

    I have another questions is

    1. if we use the WebApi. Is the configuration the same with WCF Service??
    2. if I have another [OperationContract] called Helloworld in the ISerivces, whether or not I need to add another endpoint inside?? Or don't need to do it <endpoint address="/GetData" binding="basicHttpBinding" contract="SPCustomWCF.IService1">
             
      </endpoint>



    Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.

    • Edited by Will .H Tuesday, October 22, 2019 6:31 PM
    Tuesday, October 22, 2019 1:53 PM
  • Hi Lee,

    today I follow up the above article to try the sample code once again. But today the result is difference.

    Your sample code is : client.GetData(1) BUT Today: I just only have client.GetDataAsync. I don't have GetData - this OperationContract.? so would you mind telling me where the wrong is?

    Thanks


    Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.

    Thursday, October 24, 2019 5:45 PM
  • Hi,

    I guess you selected different framework other than .Net Framework.


    For web api, I custom web api in webpart and call it from front-end usually, I have no experience to host a custom web api and call it from outside of SharePoint currently.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, October 25, 2019 3:36 AM