web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Connecting to a D365 Custom Service through service reference in Visual Studio

(0) ShareShare
ReportReport
Posted on by 300

I am having trouble creating a service reference in VS from outside my D365 dev box

The outside application currently interacts with D365 through OData using secrets and this works well. However when I tried to setup a service reference it's asking me for a user name and password. I have tried D365 admin users, tenant users, builtin admin login but it won't authenticate, what am I missing?

pastedimage1593082765790v1.png

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Have you checked the D365FO Integration Sample App? It has samples for custom services, too.

    You can install, run and debug the app locally to see how it's implemented and how it behaves.

    github.com/.../ServiceSamples

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi richerich79,

    You are trying to create a service reference for REST-based service, but it should be SOAP-based service.

    If you want to consume REST-bases service from VS, check the documentation. It contains a reference to the example project as well.

    docs.microsoft.com/.../custom-services

  • richierich79 Profile Picture
    300 on at

    Hi Sergei. I'm still banging my head against the wall with this.

    I don't think this is a REST-based service. There is a wsdl at "myendpoint?wsdl" and looking at the service it extends SysOperationServiceBase and has DataContractAttribute and DataMemberAttribute on the model contract.

    If I do treat it as a REST endpoint and put the model in the content of a http POST request I get the following error returned from the server

    {
    "Message": "An exception occured when deserializing a parameters - Exception occurred when parsing and deserializing parameter '_contract' - 'Parameter '_contract' is not found within the request content body.'",
    "ExceptionType": "XppServicesDeserializationException",
    "ActivityId": "e1eb8675-545e-0000-ca93-ebe15e54d601"
    }

    Im still in the position that I can't add the service reference

  • Martin Dráb Profile Picture
    237,963 Most Valuable Professional on at

    We can say that from the URL - you're using /api/services/ instead of /soap/services/.

    The exception is saying that you're sending wrong parameters - you must send an object containing a property named "_contract".

  • Suggested answer
    mhdshb1 Profile Picture
    1,250 on at

    Hi,

    As Martin mentioned, the service is expecting a parameter.

    This is an example how to send a contract with three properties (_worker, _dayDateFrom, _dayDateTo)

    var contract = new { _worker = empId, _dayDateFrom = fromDate, _dayDateTo = toDate };
    string json = JsonConvert.SerializeObject(contract);
    Byte[] byteArray = Encoding.UTF8.GetBytes(json);
    request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(true);
    request.Method = "POST";
    request.ContentLength = byteArray.Length;
    request.ContentType = "application/json";
    using (var stream = request.GetRequestStream())
    {
        stream.Write(byteArray, 0, byteArray.Length);
    }

    Regards,

    M

  • Suggested answer
    richierich79 Profile Picture
    300 on at

    Thanks for all your responses. You were all correct, what threw me was the object to be sent must contain the parameter in the service.

    If the service is 

    public PLMPricePriceList findEx(PLMFindPriceListContract _contract)

    I would of expected like c# REST service to be able to 

    var contract = new PLMFindPriceListContract() { _worker = empId, _dayDateFrom = fromDate, _dayDateTo = toDate };
    string json = JsonConvert.SerializeObject(contract);

    However because the service requires a parameter of name "_contract" I had to wrap the PLMFindPriceListContract in another object like below

    var contract = new PLMFindPriceListContractWrapper() { _contract = new PLMFindPriceListContract() { _worker = empId, _dayDateFrom = fromDate, _dayDateTo = toDate }};
    string json = JsonConvert.SerializeObject(contract);

    Many thanks for the comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans