question

SathishBonifash-7332 avatar image
0 Votes"
SathishBonifash-7332 asked JamesHamil-MSFT commented

Auze AD Authentication is not working inside webservice method call

Dear Experts,

I am facing challenge to implement Azure AD authentication in my existing application which is webservice (asmx) method.

I have implemented AAD authentication logic in console application its works fine with out any issue.

But its not working while i connect and getting token id its shows following error messages, could you please help to give your advices. greatly appreciated i have to complete it ASAP.

System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Threading.Tasks.Task`1[[System.Threading.Tasks.VoidTaskResult, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_Task(String n, String ns, Task o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_Task(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.TaskSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()

Code Sample:
22952-image.png


azure-active-directoryazure-ad-authenticationazure-webapps-authentication
image.png (67.9 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, are there any updates with this case? If not, please select the appropriate response as "Answered." Otherwise please let us know how we can assist you.

0 Votes 0 ·

1 Answer

soumi-MSFT avatar image
0 Votes"
soumi-MSFT answered soumi-MSFT commented

@SathishBonifash-7332, I believe the AcquireTokenForClient() function fails as it is used to implement Client_Credentials flow, but as discussed here in this thread https://docs.microsoft.com/en-us/answers/questions/86362/create-event-in-outlook-calendar-using-azure-ad-ge.html, you would need to use the Authorization Code Grant flow or OpenIDConnect to get this thing working.

You can refer to the following sample: https://github.com/AzureAdQuickstarts/AppModelv2-WebApp-OpenIDConnect-DotNet

Hope this helps.

Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SathishBonifash-7332 , Just wanted to check if the above response helped you or if there are any more queries around this so that we can help you better. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.

0 Votes 0 ·